在需要 HTTPS 连接的服务器上对 SOAP 服务使用 Visual Studio“Web 引用”时,出现错误: “底层连接已关闭:无法为 SSL/TLS 安全通道建立信任关系。”
客户端的父类是 SoapHTTPClientProtocol,如果有任何区别的话。
我不能修改服务器的证书。是否有接受证书的编程方式?
谷歌搜索我发现了几个对 ServicePointManager 类的引用,但没有一个足够全面以至于我理解如何使用它。
http://support.microsoft.com/kb/915599
有没有其他人遇到过这个错误?
最佳答案
在调用服务之前尝试调用它:
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
并将这个回调方法放在:
private static bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}
关于.Net Web 引用 SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3943589/