This is what I have in the service contract:
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
string HelloWorld(HelloWorldViewModel vm);
where HelloWorldViewModel has properties X and Y.
If I do localhost/webservices/HelloWorld?X=1&Y=2, and set a breakpoint in the HelloWorld method, vm will be null. It does not automatically bind the passed-in query string params into a view model object.
Am I missing something? Thanks!
The behavior you described is implemented specifically in ASP.NET MVC model binding.
If you want to pass a complex object to a REST service operation using the WCF Web Programming Model, you'll have to include it in its serialized form in the body of an HTTP POST request.
In your case, based on the attributes placed on the HelloWorld service operation, the request's payload should look something like this (note that XML namespace declarations are omitted):
<HelloWorld>
<vm>
<X>1</X>
<Y>2</Y>
</vm>
</HelloWorld>
Related resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With