【问题标题】:securing .svc webservice with a x509 certificate [closed]使用 x509 证书保护 .svc webservice [关闭]
【发布时间】:2014-12-01 09:25:55
【问题描述】:

我在我的服务器上托管了一个 .svc 网络服务,我们使用低行为作为测试,以确保网络服务调用者得到他们应该得到的东西。 现在我想使用 x509 证书,我有证书,需要将其发送给消费者,以便他们仔细检查是否可以交换数据。 我不确定要遵循哪些步骤 我有这两个文档,但我想与任何知道如何做得更好的人再次确认。

steps to enable x509

Pattern and practice WCF

【问题讨论】:

  • 关闭问题的原因是什么?你不明白,不知道,这太荒谬了

标签: c# web-services wcf ssl


【解决方案1】:

如果您想使用 x509 证书对调用 WCF 服务的客户端进行身份验证,那么您参考的第一篇文章是一个非常好的分步指南。 http://www.codeproject.com/Articles/36683/simple-steps-to-enable-X-certificates-on-WCF 本文假设您的客户端和服务都在同一台机器上运行,因此您需要根据具体情况调整说明。

第 1 步:创建客户端和服务器证书

由于您已经拥有证书,您可以跳过此步骤。您必须在步骤 3 和 7 中将 WcfServer 和 WcfClient 替换为您的服务器和客户端证书中的名称。

第 2 步:复制受信任的人证书中的证书

引用的文章解释了如何在 MMC 中打开证书管理单元。由于您使用的是现有证书,因此您可能需要在服务器上导入服务证书,在客户端计算机上导入客户端证书。然后导出没有私钥的客户端证书并将其导入服务器计算机上的 Trusted People 文件夹中。

步骤 3:在 WCF 服务 web.config 文件中指定证书

<serviceCredentials>
  <clientCertificate>
    <authentication certificateValidationMode="PeerTrust"/>
  </clientCertificate>
  <serviceCertificate findValue="!Insert name from your server certificate here!"
     storeLocation="LocalMachine"
     storeName="My"
     x509FindType="FindBySubjectName" />

第 4 步:在 WCF 服务 web.config 文件中定义绑定

<bindings>
  <wsHttpBinding name="wsHttpEndpointBinding">
    <binding>
      <security>
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

第 5 步:将绑定与 WCF 服务 web.config 文件中的端点绑定

<endpoint address="" binding="wsHttpBinding" 
   bindingConfiguration="wsHttpEndpointBinding" contract="WCFServiceCertificate.IService1">

第 6 步:制作用于使用 WCF 服务的 Web 应用程序客户端。

添加服务引用时,Visual Studio 会在客户端 web.config 文件中插入元素。您需要按照第 7 步和第 8 步进行修改。

步骤 7:在客户端 web.config 文件中为 WCF 客户端定义证书

<behaviors>
  <endpointBehaviors>
    <behavior name="CustomBehavior">
      <clientCredentials>
        <clientCertificate findValue="!Insert name from your client certificate here!"
            x509FindType="FindBySubjectName" 
            storeLocation="CurrentUser" storeName="My" />
      <serviceCertificate>
         <authentication certificateValidationMode="PeerTrust"/>
      </serviceCertificate>
   </clientCredentials>
 </behavior>
</endpointBehaviors>

第 8 步:在客户端 web.config 文件中将行为与 WCF 客户端上的端点绑定

您需要替换地址、合同和 dns 值以匹配您的实际 WCF 服务。

<client>
  <endpoint address="http://localhost:1387/Service1.svc" binding="wsHttpBinding"
      bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
      name="WSHttpBinding_IService1" behaviorConfiguration="CustomBehavior">
    <identity>
      <dns value="WcfServer" />
    </identity>
  </endpoint>
</client>

【讨论】:

  • 谢谢那是我的同一篇文章,但不确定它是否适用
猜你喜欢
  • 2016-12-05
  • 1970-01-01
  • 1970-01-01
  • 2014-04-04
  • 1970-01-01
  • 2016-04-17
  • 2013-01-28
  • 2010-12-10
  • 1970-01-01
相关资源
最近更新 更多