WCF Could not establish trust relationship for the SSL/TLS secure channel with authority

时光毁灭记忆、已成空白 提交于 2019-12-23 05:40:33

问题


Scenario:

I've a WCF web service called SERVICEA hosted in Azure. It's uses self signed certificate for HTTPS. This SERVICEA inspect the incoming request and determines whether to call:

  1. SERVICEB OR
  2. SERVICEC

Both SERVICEB AND SERVICEC also uses self signed cert. for https.

PROBLEM:

When I deploy the SERVICEA and try to call so that it invokes SERVICEB I get the error message below:

*

Could not establish trust relationship for the SSL/TLS secure channel with authority "SERVICEB..."

*.

Note it says SERVICEB.. on error message.

Anyidea how I can resolve this issue, please?


回答1:


You need to validate the server certificate if its self signed as shown below:

ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, error) => true;



回答2:


You want to trap the ServerCertificateValidationCallback and make it ignore certificates of your choosing. Here is a decent article that explains how: http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate-programmatically/




回答3:


Rajesh is onto something, but his answer disables certification checks altogether.

Instead I would suggest an event handler like the following should be added to your application:

ServicePointManager.ServerCertificateValidationCallback +=  (sender, certificate, chain, errors) =>
{
    var request = sender as HttpWebRequest;
    if (request != null && request.Address.Host == "<Your domain name goes here>")
        return true;

    return errors == SslPolicyErrors.None;
};


来源:https://stackoverflow.com/questions/8706947/wcf-could-not-establish-trust-relationship-for-the-ssl-tls-secure-channel-with-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!