我正在開發C#中的WCF Web服務,並使用它來測試客戶端。 Web服務託管在服務器上的IIS中,測試客戶端在桌面PC上運行。我可以使用http從客戶端調用Web服務,但現在我試圖讓它使用https和x509證書。當我嘗試撥打電話時,我收到「無法爲權限爲'192.168.5.5''的SSL/TLS安全通道建立信任關係」。以下是我到目前爲止,試圖讓這個設置完成:WCF X509獲得「無法建立具有權限的SSL/TLS安全通道的信任關係」
創建一個自簽名的證書和密鑰的證書根使用方法:
makecert -n "CN=RootTest" -r -sv RootTest.pvk RootTest.cer
創建的證書/由上述簽署的鑰匙根服務器和客戶端:
makecert -iv RootTest.pvk -n "CN=ServerTest" -ic RootTest.cer -sky exchange -pe -sv ServerTest.pvk ServerTest.cer
makecert -iv RootTest.pvk -n "CN=ClientTest" -ic RootTest.cer -sky exchange -pe -sv ClientTest.pvk ClientTest.cer
進口的RootTest.cer作爲下的服務器,並使用MMC客戶端PC上都「本地計算機」「受信任的根」。
服務器和客戶端證書/密鑰創建PFX文件:
pvk2pfx.exe -pvk servertest.pvk -pi "mypassword" -spc servertest.cer -pfx servertest.pfx -po "mypassword"
pvk2pfx.exe -pvk clienttest.pvk -pi "mypassword" -spc clienttest.cer -pfx clienttest.pfx -po "mypassword"
「本地計算機」下的服務器上導入servertest.pfx,「個人」使用MMC。
使用MMC在「本地計算機」,「個人」下的客戶端PC上導入了clienttest.pfx。
引用 「ServerTest」 在web.config中證書的服務器上:
<system.serviceModel>
<services>
<service name="MyTestService.Service" behaviorConfiguration="MyTestServiceBehavior">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureBasicHttpBinding"
contract="MyTestService.Service.IServiceContract" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myTestServiceBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<serviceCertificate storeLocation="LocalMachine" storeName="My" findValue="CN=ServerTest" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="secureBasicHttpBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
引用 「ClientTest」 作爲在PC客戶端上的app.config證書:
<system.serviceModel>
<client>
<endpoint address="https://192.168.5.5/MyTestService/Service.svc"
behaviorConfiguration="myTestClientBehavior"
binding="basicHttpBinding"
bindingConfiguration="secureBasicHttpBinding"
contract="MyTestService.Service.IServiceContract" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="myTestClientBehavior" >
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" storeName="My" findValue="CN=ClientTest" />
<serviceCertificate>
<authentication revocationMode="NoCheck" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="secureBasicHttpBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="Certificate" />
</security>
</binding>
</basicHttpBinding>
</bindings>
我在做什麼錯誤或丟失?在此先感謝您的回覆。
謝謝。我這樣做了,「證書狀態」顯示「證書沒問題」。奇怪的是顯示的「證書路徑」值不是我的web.config文件(「ServerTest」)中引用的值,而是服務器上的另一個值。我嘗試使用我期望的「ServerTest」證書的指紋將web.config更改爲FindByThumbprint,並且服務仍然使用其他證書籤名。我在web.config的指紋值中引入了一個錯字,並得到了預期的「找不到X.509證書」錯誤。代碼中沒有證書設置,全部都在web.config中。有什麼建議麼? –