Looking for some way to make one post method in WCF restful service which can accept both xml and json. I can see that is possible with Get method which automatically returns json/xml based on request header.
One solution I could think of is:
- Get the post data as “Stream” and read it to a string.
- Check request header and deserialize it to json or xml.
- Set OutgoingResponse format accrodingly and return response.
I’m able to do #1 but stuck in #2 and #3.
Microsoft has already done this for you, don’t reinvent the wheel.
You can download ASP.NET MVC4 for free which includes the new Web API. http://www.asp.net/mvc/mvc4 . This is basically the final product of the WCF Web API, which is no longer supported. Unless you have so much code already written with the original Web API that it wouldn’t be practical to make the switch, this will save you a lot of time in the long run. Otherwise you will be stuck with a Beta product that has bugs which will never be fixed.