Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServicePointManager.ServerCertificateValidationCallback not being hit

I have the following code.

public void Submit(string XML)
{
ServicePointManager.ServerCertificateValidationCallback = ValidateCertificate;
TestWS.CW serv = new TestWS.CW();
string s = serv.Check(XML);
}

private static bool ValidateCertificate(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
return true;
}

However the code never enters the ValidateCertificate method.... It does if I submit a standard HttpsWebRequest but if I use a webservice it does not work. What am I doing wrong?

like image 405
coolblue2000 Avatar asked Dec 20 '12 12:12

coolblue2000


1 Answers

Stick this in your startup code for your HTTP processing somewhere...

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

That does it for me, but I only do THIS for debug builds...

like image 55
LarryF Avatar answered Oct 25 '22 02:10

LarryF