dab*_*bor 1 c# iis wcf certificate
这已经困扰我三天了,经过大量谷歌搜索后,我决定发布一个问题。我有一个 WCF 服务应用程序(“本地服务”),它安全地连接到“远程 Web 服务”(Java)(2 路证书身份验证)。
我的服务端配置:
<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" />
Run Code Online (Sandbox Code Playgroud)
现在来说说问题。当在 Visual Studio Web Development Server 中托管服务或从本地测试客户端 (.exe) 调用远程服务时,调用会成功。但是当本地服务是 IIS 托管(本地主机或其他服务器 IIS)时,我会得到异常:
无法使用权限“ https://someserver.com:8085 ”建立 SSL/TLS 安全通道
有内部异常:
请求被中止:无法创建 SSL/TLS 安全通道。
到目前为止我尝试或检查过的内容:
另一件事:当前的远程服务器证书是为另一个主机名颁发的,因此我必须以编程方式覆盖验证。因此,要在本地服务中创建远程服务对象,我有以下代码行:
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
Run Code Online (Sandbox Code Playgroud)
我还能错过什么?有什么想法、指点吗?
好吧,回答我自己的问题。
基于此链接:如何让 ASP.NET 访问证书存储中证书中的私钥? 我解决了我的问题。
我的解决方案的关键是这个检查清单:
我几乎肯定做了所有这些事情,但显然从来没有一次全部完成。希望这对其他人有帮助。不管怎样,感谢所有的帮助。