我有一个名为“ CreateShakeoutDocument”的有效UNBOUND
OData
动作,该动作返回一个名为ShakeoutDocument的Complex Object
的有效值。我正在尝试将相邻的“ SaveShakeoutDocument”实现为UNBOUND
操作。
有效负载应类似于:{ document: { ...the Json of the Document... }}
问题
问题是...执行各种组合时,我得到的是NULL ODataActionParameters
还是空的。
EDM模型:“ SaveShakeoutDocument” :
非常标准...
var saveShakeoutDocument = modelBuilder.Action("SaveShakeoutDocument").ReturnsFromEntitySet<ShakeoutDocument>("ShakeoutDocument");
saveShakeoutDocument.Parameter<ShakeoutDocument>("document");
ODATA ACTION:“ SaveShakeoutDocument” :
非常标准...
[HttpPost]
[ODataRoute("SaveShakeoutDocument")]
public IHttpActionResult SaveDocument(ODataActionParameters parameters)
{
// Doing awesome stuff here...
}
使用HTTP客户端:“ SaveShakeoutDocument” :
“ document”变量已传入...
using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(username, password) })
using (var client = new HttpClient(handler))
{
var action = "SaveShakeoutDocument";
var URL = string.Format("{0}{1}", BASE_URL, action);
try
{
// Form Data - THIS FAILS: ODataActionParameters = NULL
var jsonObject = JsonConvert.SerializeObject(document);
var data = "{document: " + jsonObject + "}";
var payload = new StringContent(data, Encoding.UTF8, "application/json");
payload.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var httpResponse = client.PostAsync(URL, payload).Result;
var json = await httpResponse.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
Console.WriteLine("FAILURE: SaveShakeoutDocumentAsync (async)");
throw;
}
}
使用邮递员:“ SaveShakeoutDocument” :
奇怪的是...我正在回发从“ CreateShakeoutDocument”方法中收到的完全相同的Json。
标题...
原始身体看起来像...
尽管您不需要它来理解/回答问题,但Document JSON看起来却很...
{
"@odata.context": "http://localhost:50806/$metadata#ShakeoutDocument/$entity",
"DocumentTypeId": 1,
"GlobalId": "e8c9d71d-2773-e911-b71a-8cdcd4471a95",
"ParentId": null,
"AuthorId": 1,
"PublisherId": null,
"RevisionNumber": 0,
"PublishedDate": null,
"IsActive": true,
"Id": 44,
"CreateUserId": "domain\\lanid",
"CreateDate": "2019-05-10T08:25:46.31-05:00",
"UpdateUserId": "domain\\lanid",
"UpdateDate": "2019-05-10T08:25:46.31-05:00",
"ShakeoutId": 44,
"SchedulingBatch": null,
"ProductId": null,
"Gravity": null,
"Temperature": null,
"SedimentAndWater": null,
"BatchEndDate": null,
"SampleWorkedDate": null,
"Witness": null,
"Notes": null,
"Seals": [],
"Details": [],
"ObjectState": {
"@odata.type": "#StateManagement.ShakeoutDocument.New",
"Name": "New",
"Events": [
{
"@odata.type": "#StateManagement.ShakeoutDocument.IsNew",
"Name": "IsNew"
}
]
}
}