解决方法新建一个类,代码如下:
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();//证书出现问题时调用此代码