我們遇到了WCF的問題 - 嘗試連接時出現以下錯誤。對於各種配置有很多建議,嘗試過所有我們可以使用的幫助。WCF顯示403禁止使用SSL和客戶端證書
我們使用HTTPS傳輸安全性,使用我們從GoDaddy獲得的真實SSL證書。當我們瀏覽網站上的網頁時,它似乎已經安裝並正常工作。沒有身份驗證,我們可以正確連接到我們的WCF服務。
對於認證,我們使用我們自己創建的客戶端證書。在我們切換到HTTPS之前,這些客戶端證書工作正常,當時我們正在使用自簽名服務器證書的消息安全性(這很痛苦,因爲我們必須讓客戶端安裝服務器證書)。
錯誤 HTTP請求被禁止,客戶端身份驗證方案爲「匿名」。 內部異常:遠程服務器返回錯誤:(403)禁止
服務器配置文件
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WcfService1.Service1">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="NewBinding0" contract="WcfService1.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" />
</clientCertificate>
<serviceCertificate findValue="....." x509FindType="FindByThumbprint" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add scheme="https" binding="wsHttpBinding" bindingConfiguration="NewBinding0" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
客戶端配置文件
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior0">
<clientCredentials>
<clientCertificate findValue="customuser1"
storeName="TrustedPeople" x509FindType="FindBySubjectName" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="NewBinding0">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://www.insertoursitename.com/WcfService1/Service1.svc"
behaviorConfiguration="NewBehavior0" binding="wsHttpBinding"
bindingConfiguration="NewBinding0" contract="ServiceReference1.IService1"
name="wsHttpBinding_IService1" />
</client>
</system.serviceModel>
打開WCF日誌記錄:http://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx – fejesjoco 2014-12-05 19:47:30
服務器日誌沒有任何錯誤,客戶端日誌有:客戶端認證方案「匿名」禁止HTTP請求。 – John 2014-12-05 22:38:28
完整的WCF跟蹤會在客戶端和服務器端產生大量的信息。如果您的服務器沒有日誌,那麼您實際上並未打開WCF跟蹤。或者問題出現在IIS中,並且請求甚至不能到達WCF服務,但即使如此,您應該在客戶端上擁有更多的日誌。無論如何,請檢查IIS服務器是否信任客戶端證書(只需在服務器上打開客戶端證書)。 – fejesjoco 2014-12-05 23:17:41