The request failed. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

When accessing any web service you may  face below error mesage:
The request failed. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

This can be resolved by adding following code just before you access the Secure web service


ServicePointManager.ServerCertificateValidationCallback += delegate(object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};


Click here to view the original link.

By

1 comment:

  1. Just worth noting that this callback is meant to give you an opportunity to test the certificate of the server to ensure you are dealing with who you think you're dealing with. Returning true every time will work, but is effectively bypassing that opportunity.

    ReplyDelete