Reputation: 1142
I'm trying to write a service using WCF Web Api (preview 6), which passes in parameters through the route AND through the POST body. (Variable and method names changed to protect the innocent)
For example..
[WebInvoke(UriTemplate = "{routeVariableOne}/{routeVariableTwo}/StaticRoute/{postVariableOne}", Method = "POST")] public ReturnClass AddToCollection(string postVariableOne, string routeVariableOne, string routeVariableTwo) { //Do things }
So, I want to POST postVariableOne data to the url /Resource/routeVariableTwo/routeVariableTwo
When I try posting this
{ "postVariableOne": "New Value" }
Accept:application/json Content-Type:application/json Content-Length:31
http://localhost/App/api/Resource/routeVariableOne/routeVariableTwo/StaticRoute
I get Response 500/Internal Server Error. The server encountered an error processing the request. See server logs for more details. If I leave out the json post value, it at least hits my breakpoint.
Upvotes: 1
Views: 511
Reputation: 8445
Make the parameter that corresponds to the body of type ObjectContent, then use the ReadAs() [may need to be ReadAsAsync now] method on that parameter.
Upvotes: 1