.NET Web References略過SSL憑證及使用Basic authentication的方法

修改 Reference.cs
using System.Net;
 using System.Security.Cryptography.X509Certificates;  
 public class TrustAllCertificatePolicy : ICertificatePolicy
 {
  public TrustAllCertificatePolicy() {}
  public bool CheckValidationResult(ServicePoint sp,
   X509Certificate cert,WebRequest req, int problem)
  {                       
   if (req.RequestUri.AbsoluteUri == "https://yourserver/your.asmx")
    return true;
   else
    return false;
  }
 }
然後在 Construct中加入
ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
this.Credentials= new NetworkCredential("youid","yourpwd","");