這一直困擾着我三天了,經過大量的谷歌搜索後,我決定發佈一個問題。我有一個安全地連接到「遠程Web服務」(Java)的WCF服務應用程序(「本地服務」)(雙向證書認證)。從IIS託管的應用程序通過SSL訪問Web服務時出錯
我的服務端配置:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="IhAdapterPortBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://someserver.com:8085/IhAdapter" binding="basicHttpBinding"
bindingConfiguration="IhAdapterPortBinding" contract="IHAdapter.IhAdapter"
name="IhAdapterPort" behaviorConfiguration="IHAdapterEndpointBehavior" />
</client>
<services>
<service name="SomeCompany.SomeService">
<endpoint address="" binding="basicHttpBinding"
contract="SomeCompany.ISomeService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="IHAdapterEndpointBehavior">
<clientCredentials>
<clientCertificate storeLocation="LocalMachine" storeName="My" findValue="123...abc" x509FindType="FindByThumbprint"/>
<serviceCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
現在的問題。在Visual Studio Web Development Server中託管服務或從本地測試客戶端(.exe)調用遠程服務時,調用會成功。但是,當本地服務IIS託管(本地主機或其他一些服務器IIS),我得到異常:
無法建立安全通道的SSL/TLS與權威「https://someserver.com:8085」
與內部異常:
請求已中止:無法創建SSL/TLS安全通道。
我想還是至今查了一下:
- 正確的證書存儲位置(本地計算機,而不是用戶)
- 私有密鑰權限(去MMC,發現證書,右擊,所有任務,管理私鑰,設置爲所有權限授予每個人)
- IIS應用程序的用戶(連接爲)設置爲本地用戶具有管理權限
一兩件事:當前的遠程服務器cert是爲另一個主機名發佈的,所以我必須以編程方式覆蓋驗證。因此,要建立在本地服務的遠程服務對象,我的代碼theese行:
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = ((senderParam, certificate, chain, sslPolicyErrors) => true);
IHAdapter.IhAdapterClient ihAdapter = new IHAdapter.IhAdapterClient();
ihAdapter.SomeMethod(parameters); // the exception gets thrown here
還有什麼更好的缺失?任何想法,指針?
服務器是否擁有自簽名證書?驗證服務證書的頒發者在您的證書商店中是否可用。如果該服務正在使用自簽名證書,則需要覆蓋ServiceCertificateValidation方法,以繞過服務器證書驗證 – Rajesh 2013-02-20 10:02:46
對我而言,似乎我擁有以下兩個設置:issuer cert位於服務器信任庫中,ServiceCertificateValidation以編程方式覆蓋。這看起來像IIS問題,webdev服務器或獨立exe工作正常。 – dabor 2013-02-20 17:22:48
你的客戶證書是否自簽名?如果是,那麼你是否將它放在本地計算機上 - >服務器上的可信存儲 – Rajesh 2013-02-21 09:16:17