簡體   English   中英

WCF與WSHttpBinding,消息安全性,clientCredentialType =“UserName”Cerificate SelfHosted問題

[英]WCF with WSHttpBinding, Message Security, clientCredentialType=“UserName” Cerificate SelfHosted Issue

我創建了一個服務,我需要客戶端傳遞憑據(用戶名和密碼)。 此行為需要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>

Thanx提前

您的證書需要導入到托管您的Web服務的計算機上的Windows證書存儲區(即“服務器”)和(可選)導入使用您的Web服務的計算機上(即“客戶端”,如果是一台不同的機器)。

您應該使用Microsoft管理控制台(MMC)執行此操作。 首先,你應該根據其設置這個文章。 然后按照步驟導入證書文章。 確保為客戶端證書(即“個人”)和根證書(即“受信任的根證書頒發機構”)選擇正確的存儲。

除非找到配置文件中引用的正確證書,否則您的Web服務將無法啟動。 在您的情況下,這是您要存儲在“個人”商店中的"MyServerCert"證書。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM