在.NET调用加了SSL验证的WebService System.Net.WebException: 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。 —> System.Security.Authentication.AuthenticationException: 根据验证过程,远程证书无效。 你可以改进代码以询问用户证书无效。 不能恢复某些项目. 如下所示:
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
并添加如下方法:
public static bool ValidateServerCertificate(object sender,X509Certificate certificate,X509Chain chain,SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; else { if (System.Windows.Forms.MessageBox.Show("The server certificate is not valid.nAccept?","Certificate Validation", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) return true; else return false; } }