没有命中ServicePointManager.ServerCertificateValidationCallback

coo*_*000 6 c# servicepointmanager

我有以下代码.

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;
}
Run Code Online (Sandbox Code Playgroud)

但是,代码永远不会进入ValidateCertificate方法....如果我提交标准,HttpsWebRequest但如果我使用Web服务它不起作用.我究竟做错了什么?

Lar*_*ryF 7

坚持你的启动代码,以便在某处进行HTTP处理......

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
Run Code Online (Sandbox Code Playgroud)

这对我来说,但我只为调试版本做这个...