We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

Recently, I have had to face a problem while consuming a web service from my .NET application and would like to share the problem as well as the solution with others. 

The error message I received said:

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

As I later found out, this error occurs because the server in question is SSL protected but it is not using a trusted certificate. HTTPS/SSL clients always validate the SSL server certificates to ensure the identity of the server. If the server is SSL protected and is not using a trusted certificate, then the client-side will report error by default.

To resolve this problem you need to add the following code at the beginning before the service is invoked to make the client trust certain or all server certificates by using ServicePointManager.ServerCertificateValidationCallback event handler:
 
ServicePointManager.ServerCertificateValidationCallback += delegate(
Object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
//check certificate
 
return true;
};


Related Tags:

ASP.NET

Author: Saroj Dash

top

ASP.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login