Can I call a WCF service without setting content-type?

*爱你&永不变心* 提交于 2019-12-10 10:45:32

问题


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?


回答1:


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




回答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



来源:https://stackoverflow.com/questions/6054674/can-i-call-a-wcf-service-without-setting-content-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!