您的位置:首页 > 其它

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

2011-04-19 14:13 519 查看
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.

// 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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐