I have a stock WCF Rest application (default Web.config, Web Routing). I am unable to get the WCF framework to auto de-serialize the request stream into typed objects. I have a service with a method sig in the form…
[WebInvoke(Method = "POST",
UriTemplate = "",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json)]
MethodA(FirstParam first, SecondParam second)
If I initiate a request from fiddler or jQuery using $.ajax I get a 400 Bad Request error. I’ve done plenty of searching and found that changing the method sig to use a System.IO.Stream allows the method to be executed, however it also adds the overhead of de-serializing the objects.
The raw request body is as follows
{
"first":"{\"p1\":\"p1 value\",\"p2\":\"p2 value\",\"p3\":100\"p4\":null}",
"second":"{\"p1\":\"p1 value\"}"
}
Yeh the application doesn’t even break into the service itself unless the method has either a Stream, or no arguments. There is only 1 post method in this service, the other is a GET method which is working correctly.
I’ve used http://www.codeproject.com/KB/ajax/jQueryWCFRest.aspx as a reference implementation, but have been unable to get it to work on this solution.
Is there something that I’m missing here that hopefully someone else can see?
Leon
Bleh… the problem turned out to be the way the request was serializing values!
Should have been without the escaped quotes….
The reason this was happening was JSON.stringify was being called not only on the wrapped request parameters, but on each parameter as well.