开发者

.Net Web Reference SSL Error

开发者 https://www.devze.com 2023-01-20 07:22 出处:网络
While using a Visual Studio \"Web Reference\" to a SOAP service on a server that requires an HTTPS connection I get the error:

While using a Visual Studio "Web Reference" to a SOAP service on a server that requires an HTTPS connection I get the error: "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

The parent class of the client is SoapHTTPClientProtocol if that makes any difference.

I am not in the position to modify the certificate of the server. Is there a programmatic way to accept the certificate?

Googling around I found several references to the ServicePointManager class but none comprehensive enough that I understand how t开发者_JAVA技巧o make use of it.

http://support.microsoft.com/kb/915599

Has anyone else encountered this error?


Try calling this before calling the service:

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

And put this callback method in:

    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;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消