Thursday, September 4, 2014

.Net C# - How to Bypass invalid SSL certificate errors when calling web services from .Net

C# (ASP.Net) error
Error:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
and:
The remote certificate is invalid according to the validation procedure.

Below code can be used to bypass ssl related errors while calling webservices from your .net code


string sUrl = "http://mysite.com/myservice";
System.Net.WebClient client = new System.Net.WebClient();
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
string sHttpResonse = client.DownloadString(sUrl);

No comments:

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...