例外:未提供客户端证书

时间:2012-01-13 16:40:25

标签: certificate wcf-security wcf-client

我正在尝试使用安全性配置WCF服务。我已经生成了2个存储在LocalComputer \ Personal Certificates中的证书(用于服务器端和客户端)。我的配置是:

服务器

<netTcpBinding>
   <binding name="defaultBinding">
      <security mode="Transport">
         <transport clientCredentialType="Certificate"/>
      </security>
   </binding>
</netTcpBinding>

<service name="..." behaviorConfiguration="serviceBehavior">
   <endpoint address="..." binding="netTcpBinding" bindingConfiguration="defaultBinding" contract="...">
      <identity>
        <dns value="ClientSide"/>
      </identity>
    </endpoint>
 </service>

 <behavior name="serviceBehavior">
    <serviceCredentials>
       <serviceCertificate storeLocation="LocalMachine" storeName="My" findValue="ServerSide" x509FindType="FindBySubjectName"/>
       <clientCertificate>
          <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
       </clientCertificate>
    </serviceCredentials>
 <behavior>

客户端:

<netTcpBinding>
   <binding name="defaultBinding">
      <security mode="Transport">
         <transport clientCredentialType="Certificate"/>
      </security>
   </binding>
</netTcpBinding>

<endpoint name="..." binding="netTcpBinding" bindingConfiguration="defaultBinding" contract="..."
            behaviorConfiguration="endpointBehavior">
  <identity>
    <dns value="ServerSide"/>
  </identity>
</endpoint>

 <behavior name="endpointBehavior">
    <clientCredentials>
       <serviceCertificate>
          <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
       </serviceCertificate>
       <clientCertificate storeLocation="LocalMachine" storeName="My" findValue="ClientSide" x509FindType="FindBySubjectName"/>
    </clientCredentials>
 <behavior>

我收到异常:未提供客户端证书。在ClientCredentials中指定客户端证书

我尝试过很多教程,但都没有。有什么建议吗?

1 个答案:

答案 0 :(得分:6)

答案实际上是在例外中。 您没有客户端证书。您可以使用此

为客户端证书定义服务证书
<clientCredentials>
       <serviceCertificate>
          <authentication certificateValidationMode="None" revocationMode="NoCheck"/>
       </serviceCertificate>
       <clientCertificate storeLocation="LocalMachine" storeName="My" findValue="ClientSide" x509FindType="FindBySubjectName"/>
    </clientCredentials>

但您实际应该做的是为客户端定义客户端证书

<system.serviceModel>
   <behaviors>
      <endpointBehaviors>
         <behavior name="endpointBehavior">
            <clientCredentials>
               <clientCertificate storeLocation="LocalMachine" storeName="My" findValue="ClientSide" x509FindType="FindBySubjectName" />
               <serviceCertificate>
                  <authentication certificateValidationMode="None" revocationMode="NoCheck" />
               </serviceCertificate>
            </clientCredentials>
         </behavior>
      </endpointBehaviors>
   </behaviors>
</system.serviceModel>

这至少可以解决您的The client certificate is not provided. Specify a client certificate in ClientCredentials例外情况。