WCF wsHttpBinding具有证书消息安全性

时间:2011-09-21 19:07:45

标签: wcf wcf-security wshttpbinding wcf-configuration

我正在尝试使用带有证书的Message security来创建客户端和服务应用程序。但我总是有一些错误,无法使其发挥作用。有人可以建议我的配置文件有什么问题吗?

这是服务配置:

  <system.serviceModel>

<services>
  <service name="SecuredCommunication.Service1" behaviorConfiguration="securedBehavior">
    <endpoint address="test" binding="wsHttpBinding" bindingName="test" name="fasds" bindingConfiguration="securedWsBinding" contract="SecuredCommunication.IService1" >
    </endpoint>
  </service>
</services>

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

<behaviors>
  <serviceBehaviors>
    <behavior name="securedBehavior">
      <serviceMetadata httpGetBinding="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
      <serviceCredentials>
        <serviceCertificate findValue="wcftest.pvt" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
        <clientCertificate>
          <authentication certificateValidationMode="PeerTrust"/>
        </clientCertificate>
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

这是测试客户端配置

  <system.serviceModel>
<behaviors>
  <endpointBehaviors>
    <behavior>
      <clientCredentials>
        <clientCertificate findValue="wcftest.pvt" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
      </clientCredentials>
    </behavior>
  </endpointBehaviors>
</behaviors>
<bindings>
  <wsHttpBinding>
    <binding>
      <security mode="Message">
        <message clientCredentialType="Certificate"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<client>
  <endpoint address="http://wcftest.pvt/SecuredCommunication/Service1.svc" binding="wsHttpBinding" contract="SecuredCommunication.IService1">
  </endpoint>
</client>

我当前的例外是:

  

System.ServiceModel.ServiceActivationException:无法激活所请求的服务“http://wcftest.pvt/SecuredCommunication/Service1.svc”。有关详细信息,请参阅服务器的诊断跟踪日志。

对我来说配置看起来不错,我是用MSDN的一些手册创建的,所以我无法理解有什么问题。 我使用像这样的makecert.exe工具安装了证书

  

makecert.exe MakeCert -pe -ss My -sr LocalMachine -a sha1 -sky exchange -n CN = wcftest.pvt

谢谢, 亚历山大。

1 个答案:

答案 0 :(得分:0)

在服务配置中,替换

<serviceMetadata httpGetBinding="true"/> 

通过

<serviceMetadata httpsGetBinding="true"/> 

这与绑定中应用的安全通道配置相匹配。