How to accept a self-signed SSL certificate in a WCF client?

后端 未结 2 928
礼貌的吻别
礼貌的吻别 2021-01-11 17:15

This may be a stupid question but I just can\'t find the answer.

What I would like to do: I have a WCF service hosted by IIS. It is working perfectly, I can access t

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-11 17:39

    Here's the minimum amount of code you need to make WCF client accept an arbitrary certificate. This is not secure. Use for testing only. Don't blame me if this code goes berserk and eats your little kitten.

    ServicePointManager.ServerCertificateValidationCallback +=
                new System.Net.Security.RemoteCertificateValidationCallback(EasyCertCheck);
    

    The call back:

    bool EasyCertCheck(object sender, X509Certificate cert,
            X509Chain chain, System.Net.Security.SslPolicyErrors error)
    {
        return true;
    }
    

    Code shamelessly lifted from the least helpful answer to Is it possible to force the WCF test client to accept a self-signed certificate?

提交回复
热议问题