Quantcast
Channel: ASP.NET MVC / Web API / Web Pages
Viewing all articles
Browse latest Browse all 7925

New Post: HttpClient.PutAsJsonAsync(requestUri, value) does not post value to controller

$
0
0
There are really two JSON formats in play here: The AsyncEntitySetController only supports interpreting JSON data that is formatted using the various OData JSON formats. The JSON produced by JSON.NET (which is used by the default Web API JsonMediaTypeFormatter and the PostAsJsonAsync method) does not automatically conform to the OData standard – it’s really its own format. So you need to make sure you send valid OData-based JSON requests when calling your OData service.

While you could try and hand-craft OData requests using HttpClient and JSON.NET it would be difficult and error prone to do so. To call an OData service we actually recommend using the WCF Data Service Client instead of HttpClient. You can use WCF Data Service Client to consume your $metadata document and generate a strongly typed client for your OData service. You can find a sample that shows how to use the WCF Data Service Client with a Web API based OData service here.

We have had some discussions about providing a client-side OData formatter so that you could use HttpClient for these kinds of tests, but that feature hasn’t been implemented yet. Please do vote up the issue tracking this feature on our CodePlex site if this feature is important to you. Or, if you are interested in doing an implementation yourself we do accept external contributions and we would be happy to look at a pull request.

Hope this helps,

Daniel Roth

Viewing all articles
Browse latest Browse all 7925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>