سؤال

I'm trying to replace a legacy REST/plain old xml web service with a WCF one using webHttpBinding. It MUST be backwards compatible with existing clients - which currently do not send a content-type header in the requests.

When I point my clients at my new web service I get HTTP ERROR 415 - missing content type.

Is it possible to configure WCF so it will accept raw requests without a content-type header?

هل كانت مفيدة؟

المحلول 2

Under .net 3.5 the answer is NO. It seems that content-type is incorectly validated at the transport layer, instead of the application layer. The only way to get around this is to use a custom binding with a custom HtppTransportChannel.

This bug is fixed in .net 4.0

نصائح أخرى

415 is not "missing content type", it is 415 Unsupported Media Type. That infers that the server IS receiving a content-type, it just does not know how to handle it. According to the HTTP spec, proving a content-type is a SHOULD. not a MUST, so the WCF SHOULD accept a request with no content-type. If it doesn't, maybe you want to consider using the newer WCF Web API because they do follow the HTTP spec and allow you to pass content without a content-type header.


update:

Apparently this was a bug in earlier version of the .Net framework and there is a workaround/fix https://connect.microsoft.com/wcf/feedback/details/475964/content-type-header-validated-at-the-transport-level-instead-of-the-application-level-and-trows-a-415-exception

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top