WCF Could not establish trust relationship for the SSL/TLS Secure Channel With Authority

本文介绍了一种解决“无法建立SSL/TLS安全通道的信任关系”错误的方法。此问题常见于使用同一证书在不同域名(如开发或演示服务器)上托管WCF Web服务时。通过自定义远程证书验证,可以放宽严格的证书验证要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I saw people ask questions on the forums regarding to “Could not establish trust relationship for the SSL/TLS secure channel with authority” while attempting to call the web service via a host domain name other than the one specified in Issue-To within the SSL certificate. Most likely you are using the same certificate for the WCF web services hosted on other domains, for example, development or demo server.

A custom remote certificate validation can be used to avoid the strict validation, instead, just make it trust anything.

In your code, simply make a call to the static method SetCertificatePolicy() once within your application before making any request to the web services.

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;



// note this code is not intended to used 

// in production enviroment

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;

    }

}

 引用自:http://www.codemeit.com/wcf/wcf-could-not-establish-trust-relationship-for-the-ssltls-secure-channel-with-authority.html

 

转载于:https://www.cnblogs.com/zlweicoder/p/7462087.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值