没有命中ServicePointManager.ServerCertificateValidationCallback

时间:2012-12-20 12:33:20

标签: 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;
}

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

1 个答案:

答案 0 :(得分:7)

将它粘贴在您的启动代码中,以便在某处进行HTTP处理......

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

这对我来说是这样的,但我只是为调试构建做这个......