views:

16

answers:

1

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 to make use of it.

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

Has anyone else encountered this error?

A: 

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;
    }
brendan
That worked perfectly! Thanks very much Brendan.
Apathor