This project is read-only.

Content negotiation is broken (or not implemented at all)


Run the ContactManager_Advanced sample.

Issue a GET /contact/1 with "Accept: image/*". Application responds with application/xml instead of image/png as expected.

Issue a GET /contact/1 with "Accept: application/xml; q=0.8, image/png". Application responds with application/xml instead of image/png as expected.


DarrelMiller wrote Jul 4, 2011 at 7:12 PM

By default the ContactPngFormatter only supports image/png if it is explicitly requested. If you want this formatter to also be applied when the client asks for any image format then you can add the following line of code into the constructor of ContactPngFormatter


I believe this extra step is needed because, the application developer needs to tell the Web Api library which formatter should be used when a MediaRange is specified. It would be nice if it could fall back on the best match, however that introduces more magic into and already complicated process of formatter selection.

mausch wrote Jul 4, 2011 at 8:41 PM

Hi Darrell, thanks for answering. If I understood correctly, the problem with your proposed solution is that ContactPngFormatter can't respond to a request asking for image/jpeg, so isn't it technically wrong to make it accept image/* ? Moreover, this shouldn't be the responsibility of ContactPngFormatter, i.e. a formatter should only know about concrete media types, not wildcards. Otherwise they wouldn't be reusable...
I also disagree about this introducing "magic", this is just how the HTTP spec is defined...
I created a new discussion for this:


gblock wrote Aug 5, 2011 at 6:21 AM

  1. We will fix conneg to make sure the q values are working properly. It worked earlier and something broke.
  2. I filed a bug to make media type ranges work automatically through a lexical mapping. This would mean if you have a formatter that is image/png and you send image/* it would automatically match. The one cavaeat to this is if you wrote a formatter that support both image/png and say image/jpg (i.e. it dymaically creates the output in the correct format) then it would just match on the first supported media type in the formatter that matched.