2010-12-22 108 views
3

我已经创建了一个服务,我需要客户端传递凭据(用户名和密码)。此行为需要X509证书,所以我开始使用makecert.exe进行自签名开发问题。WCF与WSHttpBinding,消息安全,clientCredentialType =“用户名”证书SelfHosted问题

因为我很新手凭证,我看到这个证书是在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> 

Thanx提前

回答

3

你的证书需要导入到Windows证书存储在承载您的网站上机服务(即“服务器”)和(可选)在使用Web服务的计算机上(即“客户机”,如果它是不同的机器)。

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

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

+0

是否可以在代码中安装证书? – 2010-12-22 17:44:15