简体   繁体   English

WCF证书身份验证

[英]WCF certificate authentication

While implementiong wcf security using certificate, I am facing below mentioned error. 当使用证书实现wcf安全性时,我面临以下提到的错误。

Secure channel cannot be opened because security negotiation with the remote endpoint has failed. 无法打开安全通道,因为与远程端点的安全协商失败。 This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. 这可能是由于在用于创建通道的EndpointAddress中缺少或错误指定了EndpointIdentity所致。

I have already put the certificates in Trusted People. 我已经将证书放入“受信任的人”中。

It looks like identity problem and I have tried setting the identity both in service and client config but still it didn't work. 似乎是身份问题,我尝试在服务和客户端配置中都设置身份,但仍然无法正常工作。

Below are the configuration details. 以下是配置详细信息。

Service Configuration 服务配置

<bindings>
      <wsHttpBinding>
        <binding name="WSHTTP">
          <security mode="Message">
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>

<service name="WCFCertificateAuth.Service1">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
          bindingName="WSHTTP" contract="WCFCertificateAuth.IService1">
          <!--<identity>
            <dns value="WCfServer"/>
          </identity>-->
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 

<behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust"/>
            </clientCertificate>
            <serviceCertificate findValue="WCfServer" storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors> 

Client Configuration 客户端配置

<bindings>
            <wsHttpBinding>
                <binding name="WSHTTP_IService1" sendTimeout="00:05:00">
                    <security mode="Message">
                        <message clientCredentialType="Certificate" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>

<client>
 <endpoint address="http://localhost:8733/WCFCertificateAuth/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHTTP_IService1"
                contract="IService1" name="WSHTTP_IService1">
                <identity>
                    <dns value="WCfServer" />
                </identity>
 </endpoint>
 </client> 

<behaviors>
        <endpointBehaviors>
          <behavior>
            <clientCredentials>
              <serviceCertificate>
                <authentication certificateValidationMode="PeerTrust"/>
              </serviceCertificate>
              <clientCertificate findValue="WCfClient" storeLocation="CurrentUser" storeName="TrustedPeople" x509FindType="FindBySubjectName"/> 
            </clientCredentials>
          </behavior>
        </endpointBehaviors>
</behaviors>  

I removed the identity tag and used full name of machine in address field in place of "localhost" and its working fine. 我删除了身份标签,并在地址字段中使用了机器的全名来代替“ localhost”,并且它的工作正常。 Hope this helps anyone who is getting above mentioned error. 希望这对遇到上述错误的人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM