2011-07-10 132 views
6

我有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纔會被拒絕或找不到。

回答

7

我已經解決問題。畢竟,它不是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> 
2

假設你使用的是.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

另外,您的服務實施了多少服務合同? –