(轉自:http://blog.sina.com.cn/s/blog_5eca668b01018949.html)
定義一個類,來對遠程X.509證書的驗證,進行處理,返回為true.我們要自己定義一個類,然后在客戶單調用WCF服務之前,執行一次即可。代碼如下:
public static class Util { /// <summary> /// Sets the cert policy. /// </summary> public static void SetCertificatePolicy() {
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate; }
/// <summary> /// Remotes the certificate validate. /// </summary> private static bool RemoteCertificateValidate( object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) { // trust any certificate!!! System.Console.WriteLine("Warning, trust any certificate"); return true; }
}
你要在調用操作點先調用這個方法: Util.SetCertificatePolicy();