客户端的证书,在需要的时候在用,现在不需要客户端提供证书。
Util.SetCertificatePolicy();//强制信任证书。重写验证服务端证书的方法。
因为传输安全模式,客户端要验证服务器的证书,这里是强制验证通过。Util的代码定义如下:
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;
}
}
我们自己制作的证书容易出现这个问题。
.NET Framework 类库<!---->
ServicePointManager.ServerCertificateValidationCallback 属性<!---->
<!--Content type: DocStudio. Transform: devdiv2mtps.xslt.-->
Frank Xu Lei--谦卑若愚,好学若饥
专注于.NET平台下分布式应用系统开发和企业应用系统集成
Focus on Distributed Applications Development and EAI based on .NET
【老徐的网站】:http://www.frankxulei.com/
【老徐的博客】:http://www.cnblogs.com/frank_xl/
【WCF中文技术论坛】:微软WCF中文技术论坛
【WCF英文技术论坛】:微软WCF英文技术论坛