Formatter without preconfigured SupportedMediaTypes

Topics: Web Api
Sep 19, 2011 at 7:31 AM
Edited Sep 19, 2011 at 7:34 AM

Hello,

Hello,
first of all, I really appreciate your work with web-api. Your approach in the context of wcf is really a relieve for everybody who works on web-programming.

But I'm currently unable to find an elegant way to do the following: I have an plugin-system, which registers http-resources (ServiceContracts) at a central hosting system. This system should do error-handling, message-formatting, etc. The payload the resources do return depends on the requested Accept-header, like "application/vnd.lx-networking.inventory.stockinfo+json". This content-type should be just an alias for "application/json" (as every other media-type with the "+json" suffix should be)  and my Json.Net custom MediaTypeFormatter should be used for serialization. I tried so far to use an DelegatingHandler to add an new MediaType to the Headers.Accept collection. But when the "application/json" header is not the first one (first is my vendor-spcific one mentioned above) my custom formatter is not chosen.

So what is in the opinion of the inventors the right way to associate a media-type to an formatter on a per request basis without knowing what media-types exists upfront.
Thank you in advance.
---
Joachim