zoukankan      html  css  js  c++  java
  • The certificate that was used has a trust chain that cannot be verified问题

    今天调用wcf程序的时候发现证书有问题。报的错误如下 The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider 查找证书发现是自己的证书没有问题,服务器也是没有问题。 后来发现只要在客户端的代码添加一句话就好了。  ServiceReference1.TransportServiceClient proxy = new WCFTest2.ServiceReference1.TransportServiceClient();

     proxy.ClientCredentials.UserName.UserName = "xxxx";

     proxy.ClientCredentials.UserName.Password = "xxxx";  

    proxy.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;  //重点

    原因是我的证书放的位置不对,X509CertificateValidationMode有以下几种方式  

    None 未执行任何证书验证。  

    PeerTrust 如果证书位于被信任的人的存储区中,则有效。  

    ChainTrust 如果该链在受信任的根存储区生成证书颁发机构,则证书有效。  

    PeerOrChainTrust 如果证书位于被信任的人的存储区或该链在受信任的根存储区生成证书颁发机构,则证书有效。  

    Custom 用户必须插入自定义 X509CertificateValidator 以验证证书。

    那这个配置主要是在服务器端的配置服务器上。

    服务器的web.config配置

    <clientCertificate >

                  <certificate findValue="XuanhunClient"

                                storeLocation="CurrentUser"

                                storeName="My"

                                x509FindType="FindBySubjectName"/>

         <authentication certificateValidationMode="None" trustedStoreLocation="CurrentUser"  />

                </clientCertificate>

    服务器里面是用的none,那么客户端也需要用None.这里需要保持一致。

    但针对https里面加证书了,因为这个证书是在iis的站点增加的。所以不需要增加。

    就只要用  

    ServiceReference1.TransportServiceClient proxy = new WCFTest2.ServiceReference1.TransportServiceClient();  

    proxy.ClientCredentials.UserName.UserName = "xxxx";

     proxy.ClientCredentials.UserName.Password = "xxxx";  

    Util.SetCertificatePolicy();

    就好了。

  • 相关阅读:
    采用[ICONIX] 方法实践BLOG设计之一 [问题域建模]
    关于“三国众谋士”之IT从业可行性报告
    采用[ICONIX] 方法实践BLOG设计之二 [用例建模]
    NET框架中的 Decorator 和 Strategy 模式
    域模型向左走(充血),向右走(贫血)
    采用[ICONIX] 方法实践BLOG设计之五 [初步设计复核]
    Discuz!NT 缓存设计简析 [原创]
    Discuz!NT控件剖析 之 Tab 属性页 [原创: 附源码]
    没有银弹,但可以"扯蛋"
    Discuz!NT控件剖析 之 Button [原创: 附源码]
  • 原文地址:https://www.cnblogs.com/BinZeng/p/4123510.html
Copyright © 2011-2022 走看看