Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

generic xml/json rest wcf service

$
0
0

Hello - I read the following information online:

"The trick to getting the method to respond with and to either XML or JSON is all in the request headers. To tell the service you want to work with XML, set both the HTTP Accept and Content-Type headers to "application/xml". Then if you post XML, it will be deserialized and the return object will be serialized into XML. If you want JSON, set both to "application/json"

In concept this seems like a good way for WCF REST services to be generic enough to support SOAP and JSON communication with a single method. Is this the recommended way to provide WCF REST services these days?

I was able to set the Content-Type request header to application/xml to communicate with the WCF REST service via XML.  Then I was able to set the Content-Type request header to application/json to communicate with the WCF REST service via JSON. However, although my request was received in JSON my response was returned in XML. What do I need to change to ensure the WCF REST service returns its response as JSON in this scenario?


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>