WebAPI コントローラーに複数のパラメーターを投稿しようとしています。1 つのパラメーターは URL からのもので、もう 1 つは本文からのものです。ここにURLがあります:
/offers/40D5E19D-0CD5-4FBD-92F8-43FDBB475333/prices/
これが私のコントローラーコードです:
public HttpResponseMessage Put(Guid offerId, OfferPriceParameters offerPriceParameters)
{
//What!?
var ser = new DataContractJsonSerializer(typeof(OfferPriceParameters));
HttpContext.Current.Request.InputStream.Position = 0;
var what = ser.ReadObject(HttpContext.Current.Request.InputStream);
return new HttpResponseMessage(HttpStatusCode.Created);
}
本文の内容は JSON です。
{
"Associations":
{
"list": [
{
"FromEntityId":"276774bb-9bd9-4bbd-a7e7-6ed3d69f196f",
"ToEntityId":"ed0d2616-f707-446b-9e40-b77b94fb7d2b",
"Types":
{
"list":[
{
"BillingCommitment":5,
"BillingCycle":5,
"Prices":
{
"list":[
{
"CurrencyId":"274d24c9-7d0b-40ea-a936-e800d74ead53",
"RecurringFee":4,
"SetupFee":5
}]
}
}]
}
}]
}
}
offerPriceParameters
デフォルトのバインディングがコントローラーの引数にバインドできない理由は何ですか? 常に null に設定されます。しかし、を使用して本体からデータを回復できDataContractJsonSerializer
ます。
引数の属性も使用しようとしましたFromBody
が、どちらも機能しません。