WCF的Service用客户端去访问时加SSL验证

1.选择IIS Management打开Server Certificates

2.选择Create Selt—Signed Certificates

为你的SSL取一个名字:TestSSL

3.下来把SSL证书绑定到你的站点:

4.这样就可以用https去访问了,

5.但是我们用客户端访问时必须加上证书信任才可以去访问:

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;
        }
    }


 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章