I have a working UNBOUND
OData
action named "CreateShakeoutDocument" that returns valid of a Complex Object
, named ShakeoutDocument. I am trying to implement the adjoining "SaveShakeoutDocument" as an UNBOUND
action.
The payload should look like: { document: { ...the Json of the Document... }}
THE PROBLEM
The problem is...in executing various combinations, I either get a NULL ODataActionParameters
or I get an EMPTY one.
- I have tried using HttpClient...without success
- I have tried using Postman...without success
EDM MODEL: "SaveShakeoutDocument":
Very standard...
var saveShakeoutDocument = modelBuilder.Action("SaveShakeoutDocument").ReturnsFromEntitySet<ShakeoutDocument>("ShakeoutDocument");
saveShakeoutDocument.Parameter<ShakeoutDocument>("document");
ODATA ACTION: "SaveShakeoutDocument":
Very standard...
[HttpPost]
[ODataRoute("SaveShakeoutDocument")]
public IHttpActionResult SaveDocument(ODataActionParameters parameters)
{
// Doing awesome stuff here...
}
USING HTTP-CLIENT: "SaveShakeoutDocument":
The "document" variable is passed-in...
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;
}
}
USING POSTMAN: "SaveShakeoutDocument":
The odd thing is...I am posting back the EXACT SAME Json that I receive from the "CreateShakeoutDocument" method.
- This results in an empty ODataActionParameters
Headers...
- Content-Type: application/json
The Raw Body looks like...
- { document: { ...the Json of the Document... } }
Although you don't need it to understand/answer the question, the Document JSON looks like...
{
"@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"
}
]
}
}