<basicHttpBinding> 的 <message>

定義 <basicHttpBinding> 之訊息層級安全性的設定。

<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding>
          <security>
            <message>

Syntax

<message algorithmSuite="Basic128/Basic192/Basic256/Basic128Rsa15/Basic256Rsa15/TripleDes/TripleDesRsa15/Basic128Sha256/Basic192Sha256/TripleDesSha256/Basic128Sha256Rsa15/Basic192Sha256Rsa15/Basic256Sha256Rsa15/TripleDesSha256Rsa15"
         clientCredentialType="UserName/Certificate" />

屬性和項目

下列各節說明屬性、子元素和父元素

屬性

屬性 描述
algorithmSuite 設定訊息加密和金鑰包裝演算法。 此屬性的型別為 SecurityAlgorithmSuite,它會指定演算法和金鑰大小。 這些演算法會對應到安全性原則語言 (WS-SecurityPolicy) 規格中所指定的演算法。

預設值是 Basic256
clientCredentialType 指定當使用訊息安全性執行用戶端驗證時,要使用的認證類型。 預設值為 UserName

clientCredentialType 屬性

描述
UserName - 用戶端必須使用 UserName 認證向伺服器進行驗證。 此認證必須使用 <clientCredentials> 元素指定。
- WCF 不支援傳送密碼摘要,也不支援使用密碼衍生金鑰,以及將這類金鑰應用在訊息安全性上。 因此,WCF 會在使用 UserName 認證時強制保護傳輸。 對於 basicHttpBinding,這需要設定 SSL 通道。
憑證 需要使用憑證對伺服器驗證用戶端。 此案例中的用戶端認證必須使用 <clientCredentials><clientCertificate> 指定。 此外,當使用訊息安全性模式時,必須提供服務憑證給用戶端。 此案例中的服務認證必須使用 ClientCredentials 類別或 ClientCredentials 行為元素指定,並使用 <serviceCertificate> 指定服務憑證。

子元素

父項目

元素 描述
<security> 定義 <basicHttpBinding> 的安全性功能。

範例

這個範例會示範如何實作一個使用 basicHttpBinding 和訊息安全性的應用程式。 在下列服務組態範例中,端點定義會指定 basicHttpBinding,並參考名為 Binding1 的繫結組態。 服務對用戶端驗證它自己時所使用的憑證是在組態檔案 behaviors 區段中的 serviceCredentials 項目下設定。 用戶端用來對服務驗證本身之憑證所套用的驗證模式,也是在 behaviors 項目下的 clientCertificate 區段中設定。

相同的繫結和安全性詳細資訊是在用戶端組態檔中設定。

<system.serviceModel>
  <services>
    <service name="Microsoft.ServiceModel.Samples.CalculatorService"
             behaviorConfiguration="CalculatorServiceBehavior">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
        </baseAddresses>
      </host>
      <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/ServiceModelSamples/service -->
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="Binding1"
                contract="Microsoft.ServiceModel.Samples.ICalculator" />
      <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>
  <bindings>
    <basicHttpBinding>
    <!-- This configuration defines the SecurityMode as Message and
         the clientCredentialType as Certificate. -->
      <binding name="Binding1">
        <security mode = "Message">
          <message clientCredentialType="Certificate" />
        </security>
      </binding>
    </basicHttpBinding>
  </bindings>
  <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
  <behaviors>
    <serviceBehaviors>
      <behavior name="CalculatorServiceBehavior">
        <serviceMetadata httpGetEnabled="True" />
        <serviceDebug includeExceptionDetailInFaults="False" />
        <!-- The serviceCredentials behavior allows one to define a service certificate.
             A service certificate is used by a client to authenticate the service and provide message protection.
             This configuration references the "localhost" certificate installed during the setup instructions. -->
        <serviceCredentials>
          <serviceCertificate findValue="localhost"
                              storeLocation="LocalMachine"
                              storeName="My"
                              x509FindType="FindBySubjectName" />
          <clientCertificate>
            <!-- Setting the certificateValidationMode to PeerOrChainTrust means that if the certificate
               is in the user's Trusted People store, then it will be trusted without performing a
               validation of the certificate's issuer chain. This setting is used here for convenience so that the
               sample can be run without having to have certificates issued by a certification authority (CA).
               This setting is less secure than the default, ChainTrust. The security implications of this
               setting should be carefully considered before using PeerOrChainTrust in production code. -->
            <authentication certificateValidationMode="PeerOrChainTrust" />
          </clientCertificate>
        </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

另請參閱