2010-09-29 98 views
2

我正在嘗試創建一個WCF服務與匿名身份驗證。當我將服務部署到目前不在我當前域的目標服務器時,我嘗試調用它時收到以下錯誤:WCF服務綁定wsHttp與基本沒有身份驗證

內容類型application/soap + xml; charset = utf-8不支持 服務http://myserver.com/page.svc。 客戶端和服務綁定可能是 不匹配。

因爲目前的情況是我在爲我服務的web.config文件中的以下部分:

<system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior> 
      <serviceMetadata httpGetEnabled="true"/> 
      <serviceDebug includeExceptionDetailInFaults="false"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> 
    </system.serviceModel> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
    </modules> 
    </system.webServer> 

我一直在嘗試不同的綁定(的wsHttpBinding和basicHttpBinding的),但我要麼收到上述錯誤(使用basicHttpBinding)或「訪問被拒絕」消息(使用wsHttpBinding)。以下是我在使用wsHttpBinding時試圖使用的web.config部分

<system.serviceModel> 
    <services> 
    <service behaviorConfiguration="AMP.MainBehavior" name="AMP.Main"> 
    <endpoint address="" binding="wsHttpBinding" contract="AMP.IMain"> 
     <identity> 
     <dns value="myservice.com"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
    </services> 
    <behaviors> 
    <serviceBehaviors> 
    <behavior name="AMP.MainBehavior"> 
    <serviceMetadata httpGetEnabled="true"/> 
    <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
    </behaviors> 
</system.serviceModel> 

該服務已使用.NET 4.0框架創建。我需要它是匿名的,但我不確定我錯過了什麼。我是WCF的新手,所以我沒有連續排好所有的鴨子。

謝謝

+0

什麼是客戶端的配置? – 2010-09-29 11:43:33

回答

4

錯誤表示您發送的HTTP請求的內容類型不受支持。提到的內容類型在SOAP 1.2中使用,但BasicHttpBinding使用具有不同內容類型(text/xml; charset = utf-8)的SOAP 1.1。因此,您的服務和客戶端配置之間可能存在一些不匹配。

在你的第二個例子中,問題是默認的WsHttpBinidng配置。 WsHttpBinding在默認情況下使用郵件安全性進行保護,Windows身份驗證= >異常,因爲計算機位於不同的域中,因此Windows auhtentication無法工作。你必須定義你自己的WsHttpBinding配置。試試這個(客戶端必須使用相同的綁定配置):

<system.serviceModel> 
    <bindings> 
    <wsHttpBinding> 
     <binding name="Unsecured"> 
     <security mode="None" /> 
     </binding> 
    </wsHttpBinding> 
    </bindings> 
    <services> 
    <service ...> 
     <endpoint address="..." contract="..." 
     binding="wsHttpBinding" bindingConfiguration="Unsecured" /> 
     ... 
    </service> 
    </services> 
</system.serviceModel> 
+1

謝謝你的迴應!我在你建議的配置中添加了,並將終端地址設置爲服務所在的URL,現在我收到了一個不同的錯誤。它以「由於與遠程端點的安全協商失敗而無法打開安全通道」開始。 – 2010-09-29 12:03:45