Content negotiation in Rest service WCF

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

Hi,

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.

 

Regards

Sundarram. R

Nov 17, 2011 at 9: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:

http://codepaste.net/wehh49