【问题标题】:WCF with WSHttpBinding, Message Security, clientCredentialType="UserName" Cerificate SelfHosted IssueWCF 与 WSHttpBinding、消息安全、clientCredentialType="UserName" 证书自托管问题
【发布时间】:2010-12-22 13:39:47
【问题描述】:

我创建了一个需要客户端传递凭据(用户名和密码)的服务。此行为需要 X509 证书,因此我开始使用 makecert.exe 使用自签名证书解决开发问题。

因为我是证书新手,所以我看到这个证书是在 IIS 服务器证书部分创建的,我需要稍后在 Windows 服务上自行托管我的服务,出于测试目的,我使用控制台主机应用程序和简单的 winform 应用客户端。

所以我的问题是,如何部署此证书?无论如何我都不想使用 IIS,我可以将证书嵌入到我注意到我可以在控制台/Windows 服务主机中导出为 .pfx 文件的地方?怎么做?

我正在发布我的服务和客户端配置文件,以帮助了解我的需求。

服务器配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="B2B.WCF.Service.B2BService" behaviorConfiguration="wsBehavior">
        <endpoint name="WSHttpEndpointB2B"
                  bindingConfiguration="WSBinding"
                  address ="http://localhost:8768/ServB2B"
                  binding="wsHttpBinding"
                  contract="B2B.WCF.Contracts.IB2BContracts">
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="wsBehavior">
          <serviceMetadata httpsGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <serviceCertificate findValue="MyServerCert" x509FindType="FindBySubjectName" 
                                storeLocation="LocalMachine" storeName="My" />
            <userNameAuthentication userNamePasswordValidationMode="Custom" 
                                    customUserNamePasswordValidatorType="B2B.WCF.Service.UserValidator, B2B.WCF.Service" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="WSBinding">
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

客户端配置:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <client>
      <endpoint name="WSHttpEndpointB2B"
                bindingConfiguration="WSBinding" behaviorConfiguration="wsBehavior"
                address ="http://localhost:8768/ServB2B"
                binding="wsHttpBinding"
                contract="B2B.WCF.Contracts.IB2BContracts">
        <identity>
          <dns value="MyServerCert"/>
        </identity>
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="wsBehavior">
          <clientCredentials>
            <clientCertificate findValue="MyServerCert" x509FindType="FindBySubjectName"
                                storeLocation="LocalMachine" storeName="My"/>
            <serviceCertificate>
              <authentication certificateValidationMode="None"/>
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="WSBinding">
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

提前感谢

【问题讨论】:

    标签: wcf deployment embed wcf-security x509certificate


    【解决方案1】:

    您的证书需要导入托管 Web 服务的机器(即“服务器”)和(可选)使用 Web 服务的机器(即“客户端”,如果是不同的机器)。

    您应该使用 Microsoft 管理控制台 (MMC) 来执行此操作。首先,您应该根据this文章进行设置。然后根据this 文章中的步骤导入您的证书。确保为客户端证书(即“个人”)和根证书(即“受信任的根证书颁发机构”)选择正确的存储。

    除非找到配置文件中引用的正确证书,否则您的 Web 服务不会启动。在您的情况下,这是您要存储在“个人”存储中的 "MyServerCert" 证书。

    【讨论】:

    • 是的,但我不建议这样做。证书管理应在外部完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    相关资源
    最近更新 更多