如何使 WCF webHttp 行为接受 HEAD 动词?
我有一个托管在 Windows 服务中的 WCF 服务。 我向其中添加了一个具有 webHttp 行为的 webHttpBinding,每当我向它发送 GET 请求时,我都会得到 http 200,这就是我想要的,问题是每当我向它发送 HEAD 请求时,我都会得到 http 405。
有没有办法让它也为 HEAD 返回 http 200 ? 这可能吗?
编辑:这是运营合同:
[OperationContract]
[WebGet(UriTemplate = "MyUri")]
Stream MyContract();
I have a WCF service hosted in a Windows service.
I've added to it a webHttpBinding with a webHttp behaviour and whenever I send it a GET request I get http 200 which is what I want, problem is I get an http 405 whenever I send it a HEAD request.
Is there a way to make it return http 200 also for HEAD?
Is that even possible?
edit: that's the operation contract:
[OperationContract]
[WebGet(UriTemplate = "MyUri")]
Stream MyContract();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上面的代码工作正常。我收到 HEAD 请求的 405(方法不允许)。我使用的程序集版本是 System.ServiceModel.Web,Version=3.5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35。
实际上,据我所知,没有直接的方法允许它。但是您可以尝试类似下面的解决方案。但是必须对每个需要 GET 和 HEAD 的方法执行此操作,这使得它成为一个不太优雅的解决方案..
公共类服务:IService
{
#region IService 成员
The above code works fine. I get a 405 (Method not allowed) on HEAD request. The version of assembly I am using is System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
Actually as far as I know there is no straight forward way of allowing it.However you could try something like the solution below..But this has to be done for each method that needs GET and HEAD, which makes it a not so elegant solution..
public class Service : IService
{
#region IService Members
听起来像是服务(甚至框架)中的严重错误。 HTTP/1.1 中对 HEAD 的支持绝不是可选的。
Sounds like a serious bug in the service (or even the framework). Support for HEAD in HTTP/1.1 is in no way optional.