Can I call a WCF service without setting content-t

2019-05-18 09:06发布

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条回答
Explosion°爆炸
2楼-- · 2019-05-18 09:08

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

查看更多
该账号已被封号
3楼-- · 2019-05-18 09:10

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

查看更多
登录 后发表回答