1

Can a RESTFul service's request and response be serverd dynamically based on the "Accept" property of the client

i.e. If the client can "Accept" application/xml then my service should automatically understand that the request and response should be of type xml and process the request accordingly.

Hence, I would not create another service for client who want request/response in json and the same service should be able to handle it.

Rajesh
  • 7,766
  • 5
  • 22
  • 35

3 Answers3

1

Yes, in fact WCF can be configured to do this for you: WCF Web HTTP Formatting

When enabled, automatic formatting chooses the best format in which to return the response. It determines the best format by checking the following, in order:

  1. The media types in the request message’s Accept header.
  2. The content-type of the request message.
  3. The default format setting in the operation.
  4. The default format setting in the WebHttpBehavior.

Also, see the documentation for <webHttpEndpoint>, specifically the automaticFormatSelectionEnabled attribute.

Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
0

Yes! It probably should be the preferred way to negotiate content type.

That said, a content type override you can specify in an URL can be convenient to debug GETs from a browser. (i.e. myResource.json will be equivalent to myResource with Accept json)

ptyx
  • 4,074
  • 1
  • 19
  • 21
0

This is really easy with WCF Web Api Content negotiation. Just set the Accept Header and it's done.

Neil Thompson
  • 6,356
  • 2
  • 30
  • 53