C#动态调用webService出现 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系

解决方法新建一个类,代码如下:

1 public static class CertificateTrust
2 {
3
4 public static void SetCertificatePolicy()
5 {
6 ServicePointManager.ServerCertificateValidationCallback
7 += RemoteCertificateValidate;
8 }
9 private static bool RemoteCertificateValidate(
10 object sender, X509Certificate cert,
11 X509Chain chain, SslPolicyErrors error)
12 {
13
14 System.Console.WriteLine(“Warning, trust any certificate”);
15 return true;
16 }
17 }

//调用webservice前写上此方法即可
CertificateTrust.SetCertificatePolicy();//证书出现问题时调用此代码

你可能感兴趣的:(c#,ssl,安全)