When requesting an object for example using REST, is it possible to get the response in json and xml format or do I have to create UriTemplates that are something like:
[WebInvoke(UriTemplate="&format=json?user/{id}", ResponseFormat=WebMessageFormat.Json)]
[WebInvoke(UriTemplate="&format=xml?user/{id}", ResponseFormat=WebMessageFormat.Xml)]
The reason I ask is because I may need one format returned for an app on an android phone for example and another type returned for an app on a laptop.
Also, Can the methods have the same name such as Register or do I have to have one called:
RegisterJSON(User user) and another called RegisterXML(User user)
It is available out of the box in WCF 4 (.NET 4.0). Check AutomaticFormatSelectionEnabled property of WebHttpBehavior. You can also set this property from configuration. I showed the example here.
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