This project is read-only.

Content negotiation in Rest service WCF

Topics: Web Api
Jul 5, 2011 at 3:44 PM


How to implement content negotiation in the WCF restful service.  i.e. The return type should change based on the Content-type and Accept specified in the request header.

Example: Content-type: Application\myapp-name+xml - should return xml

and applicaiton\myapp-namme+json header should retun json.



Sundarram. R

Nov 17, 2011 at 10:00 AM

Create a DelegatingHandler - in this handler, examine the Content-type header and based on the value, clear the "Accept" header and set it to json or xml. Here's a related example by Glen Block: