Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make https request to wcf service: The remote certificate is invalid according to the validation procedure

I have a service hosted over http/https on my local machine. When I consume the service over http it works perfectly. It also works when I make https request on ajax. But it's not work, when I try to consume it from code behind of client app. It shows the an error message as follows:

"The remote certificate is invalid according to the validation procedure"

Can somebody help me out?

like image 398
surya narayana dash Avatar asked Aug 25 '14 12:08

surya narayana dash


1 Answers

This is because, the certificate you use on your local IIS, is a virtual one. Probably, you will not get it in real time. There are several hacks available to make it work locally.

NOTE: Never ever do this on production...

Add following code segment(an event handler), before calling any method of service.

 ServicePointManager.ServerCertificateValidationCallback +=
        EasyCertCheck;

 bool EasyCertCheck(object sender, X509Certificate cert,
   X509Chain chain, System.Net.Security.SslPolicyErrors error)
    {
        return true;
    }
like image 77
Rasmita Dash Avatar answered Oct 04 '22 08:10

Rasmita Dash