.NET 4 WCF SOAP服务Http POST返回404 NOT Found

.NET 4 WCF SOAP服务Http POST返回404 NOT Found

问题描述:

我有WCF托管的SOAP服务,我可以从浏览器以及从我的SOAP客户端打出HTTP GET请求,但是,在执行任何操作时HTTP POST请求,响应是404 Not Found。.NET 4 WCF SOAP服务Http POST返回404 NOT Found

我的web.config看起来像:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
      <behavior> 
       <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
       <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
       <serviceDebug includeExceptionDetailInFaults="true"/> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /> 
    <bindings> 
     <wsHttpBinding> 
      <binding> 
       <security mode="Transport"> 
        <transport clientCredentialType="Certificate" /> 
       </security> 
       <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      </binding> 
     </wsHttpBinding> 
     <basicHttpBinding> 
      <binding> 
       <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      </binding> 
     </basicHttpBinding> 
    </bindings> 
</system.serviceModel> 

我的服务就是在标记使用.svc文件的定义:

<%@ ServiceHost Language="C#" Debug="true" Service="Boca.WebServices.Billing.QBService" CodeBehind="QBService.svc.cs" %> 

同样,我可以使用浏览器打我的服务,

我在做什么错?我不应该使用.svc标记,只需在Web.config中定义我的服务?

UPDATE:

当我在本地主机使用IIS快速从内VS 2010 “开始调试” 我的WCF项目:8181端口,将HTTP POST到服务工作。只有在通过IIS托管服务时,服务的HTTP POST才会被拒绝或找不到。

我已经解决问题。毕竟,它不是IIS问题,而是我没有配置<basicHttpBinding><security>节点的问题。我没有彻底阅读关于绑定以及它们如何工作的内容,所以我认为在<basicHttpBinding>旁边添加<wsHttpBinding>将为WCF添加SSL支持。

这样做并且使用<security>节点配置默认<wsHttpBinding>确实允许我安全地获取SOAP元数据,尽管它在内部仍然使用<basicHttpBinding>,但是不支持POST。

我更新了配置,以便transport clientCredentialType设置为None和解决的问题:

<bindings> 
    <basicHttpBinding> 
     <binding name="QBService_BasicHttpBinding"> 
      <security mode="Transport"> 
       <transport clientCredentialType="None" /> 
      </security> 
      <readerQuotas maxDepth="15" maxStringContentLength="524288" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
     </binding> 
    </basicHttpBinding> 
</bindings> 

假设你使用的是.NET 4您的服务将在一个或多个端点使用basicHttpBinding的侦听 - 这是默认的,如果如果你只有一个服务合同,你不使用HTTP

时指定端点那么你的服务将以.svc结尾的地址监听HTTP POST。如果你有一个以上的服务合同,那么它在像<path to .svc>/<serviceContractname>

地址的主机上的每个合同中的服务期待SOAP请求,所以你将需要将一个SOAP 1.1(basicHttpBinding的默认为该)相匹配的XML文档。最简单的方法是在客户端项目中使用Add Service Reference构建代理,并通过生成的代理类进行调用--WCF管道将生成相应的消息并将其发布到服务

+0

的问题是,做一个HTTP POST出现了404,而做一个HTTP GET工作。另外,我注意到,如果我使用VS 2010中的IIS Express来调试VS 2010 WCF项目,那么HTTP POST的服务工作正常。它似乎只有通过IIS托管时,我看到了这种行为。 –

+0

我认为将其视为“检索元数据工作但使服务请求失败并使用404”会更有用。我假设你正在使用添加服务引用或浏览器进行GET,并且使用请求认为生成的代理的POSTs是否正确? –

+0

另外,您的服务实施了多少服务合同? –