具有证书消息安全性的 WCF wsHttpBinding

发布于 2024-12-05 13:12:55 字数 2747 浏览 0 评论 0原文

我正在尝试使用带有证书的消息安全性创建客户端和服务应用程序。但我总是遇到一些错误,无法使其工作。有人可以建议我的配置文件有什么问题吗?

这是服务配置:

  <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 交换 -n CN=wcftest.pvt

谢谢, 亚历山大.

I am trying to create client and service applications with Message security with Certificate. But I have some errors all the time and can't make it work. Could somebody suggest what is wrong with my configuration files?

This is the service configuration:

  <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"/>

and this is the test client configuration

  <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>

the current exception I have is:

System.ServiceModel.ServiceActivationException: The requested service, 'http://wcftest.pvt/SecuredCommunication/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.

For me configuration looks ok, I created it using some manuals from MSDN, so I can't understand what is wrong.
I installed certificate using makecert.exe tool like this

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

Thanks,
Alexander.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傾旎 2024-12-12 13:12:55

在服务配置中,替换

<serviceMetadata httpGetBinding="true"/> 

<serviceMetadata httpsGetBinding="true"/> 

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

In the service configuration, replace

<serviceMetadata httpGetBinding="true"/> 

by

<serviceMetadata httpsGetBinding="true"/> 

This matches the secure channel configuration applied in the bindings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文