您当前的位置: 首页 >  ssl

[C#]在.NET调用加了SSL验证的WebService-根据验证过程远程证书无效

发布时间:2017-11-21 14:30:36 ,浏览量:0

在.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; }
}
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    105695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0476s