Someone asked me recently a quick question on how to set up a RESTful service to return JSON instead of XML. Th person already had a RESTful service they had created in WCF that returned XML, so most of the hard work was done already. This was a quick answer (nice to have a quick question/answer once in a while!) since the WebGetAttribute class expose a property called ResponseFormat which accepts a WebMessageFormat enumeration value. The values are Xml and Json. So to configure a method to return a Product class serialized as JSON, simply do this:
To Flip this to return XML instead, modify the example to set the ResponseFormat to WebMessageFormat.Xml
And that’s it!