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

Does WCF Web API officially support content negotiation? I was just checking out the samples and found it's either very broken or not implemented at all: . Is this a bug in the sample app or in WCF?

BTW: can you please fix the reference paths? I wasted time looking up the libs:


Jul 6, 2011 at 8:59 PM

mausch wrote: 

 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/*

If the client passes an Accept header with only image/jpeg then the server has two choices, either it can return a 406 error code to indicate that it does not support that format, or it can return the png anyway.  The HTTP spec allows for this.  I'm not sure if it is possible to throw a HttpResponseException from within the formatter, but that would be the first place I would try if I was attempting to return a 406.

I'm not saying that the way conneg is defined in the spec is magic, I'm saying the way formatters are selected at the moment is pretty convoluted.  You may be right though that doing the wildcard mapping may make sense to do at a higher level than the formatters themselves.

Aug 4, 2011 at 7:33 AM

You can throw an HttpResonseMessage in a formatter.

Aug 4, 2011 at 8:17 AM

Mausch, looks like our conneg is broken at least in the current bits with regards to qaulifiers. I will make sure this gets fixed. I guarantee that it was not intented to work that way. :-)



Aug 5, 2011 at 5:20 AM

Update on this, I discussed this with the team and filed 2 bugs

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.

Thanks for the feedback