![](/img/trans.png)
[英]“could not establish secure channel for ssl/tls with authority” when calling WCF service on specific server
[英]Could not establish secure channel for SSL/TLS with authority when calling third party web service along with certificate
我的项目使用Visual Studio 2010,并且是一个使用c#的Web应用程序项目。 我为Web服务添加Web引用。
当我尝试使用UAT服务器中的证书访问第三方Web服务时,无法使用授权建立SSL / TLS的安全通道 。 证书已过期。 我已经为本地计算机和当前用户添加了信任根证书和个人证书。 当我使用Web服务应用程序调用但不适用于Web应用程序时,它可以工作
下面的代码我用来在调用Web服务时添加证书并绕过证书错误。
AServiceReference.AServiceClient client = new AServiceReference.AServiceClient();
X509Certificate2 cert = new X509Certificate2("CERTIFICATE","PASSWORD");
client.ClientCredentials.ClientCertificate.Certificate = cert;
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
将其添加到您的web.config文件中,可能会很好:
<bindings>
<basicHttpBinding>
<binding name="xxxBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
当我负责附加客户证书时,我可以通过以下两种方法之一来完成。 看起来您实际上并没有在任何地方附加客户端证书(如果使用的是客户端证书)。
1:通过您一直在执行的代码
proxyClient.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser,
StoreName.My,
X509FindType.FindByThumbprint,
"6D0DBF387484B25A16D0E3E53DBB178A366DA954");
2:通过在web / app.config文件中进行配置。
<behaviors>
<endpointBehaviors>
<behavior name="ohBehave">
<clientCredentials useIdentityConfiguration="false">
<clientCertificate findValue="c6dafea24197cd6a6f13e846ffcdf70220d23ec2" storeLocation="CurrentUser"
x509FindType="FindByThumbprint" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://myservice.ca/SubmitService/Submit.svc"
behaviorConfiguration="ohBehave" binding="customBinding" bindingConfiguration="SubmitBinding"
contract="SubmitService.Submit" name="SubmitDev" />
</client>
只要证书在指定的商店中,就应该附加该证书。
我还必须在.config文件中使用customBinding,因为我们也想传递凭据(请注意客户端证书的httpsTransport节点):
<binding name="SubmitBinding">
<security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
<localClientSettings detectReplays="false" />
<localServiceSettings detectReplays="false" />
</security>
<textMessageEncoding messageVersion="Soap11">
<readerQuotas maxDepth="32" maxStringContentLength="200000000"
maxArrayLength="200000000" maxBytesPerRead="200000000" />
</textMessageEncoding>
<httpsTransport maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000"
maxBufferSize="200000000" requireClientCertificate="true" />
</binding>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.