I have a wcf restful service with a operation contract that contains two values – an int and a string. This is a post call as well.
If i wrap the call using the BodyStyle = WebMessageBodyStyle.Wrapped. What should i assume the xml request will now look like?
I ran into the same problem and I believe there are a couple of ways that you can consider doing this. If there are more I’d love to hear them from others.
First, I’ll tell you how I accomplished this. Step one is to build a utility library that contains a class definition for your data object structure, with appropriate get methods and constructor to initilize the object. Also, you must make the class serializable i.e.
}
It is important to put this in a library so you can reference it from both the client and server side.
Once you’ve done that, change your WCF service method to look similar to the following:
Once this is complete, publish your service, and then use the help page from your service to view the XML syntax that is required. You can then build your XML using Linq to XML and thereby send your data object over the web as a request. This eliminates the need to wrap and exposes your request xml syntax:
Reference the utility library in your client and create a method in your data later to call the service method, creating the element in your method.
The other thing you can do is redesign your uri to be something like this:
yourdesignedURI/{myInt}/{myString}
and then use JSON Serialization to send the object. If you add the line
To your WebInvoke attribute, the help page will expose the full URI for easy viewing.
I am sure there is probably a way to do it with JQuery as well. Would love to see other solutions to this!
Hope that helps.