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

来源:互联网 发布:程序员加班猝死 编辑:程序博客网 时间:2024/04/27 23:56

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


 

 

 

原创粉丝点击