WCF常用安全方案(六)

來源:互聯網
上載者:User

匿名用戶端的訊息安全

下面的方案示範通過 Windows Communication Foundation (WCF) 訊息安全進行保護的用戶端和服務。其設計目的是使用訊息安全而非傳輸安全,以便將來可支援更加豐富的基於聲明的模型。有關 將豐富聲明用於授權的更多資訊,請參見使用標識模型管理聲明和授權。

有關應用程式範例,請參見Message Security Anonymous。


特徵 說明

安全模式

訊息

互通性

僅 WCF

身分識別驗證(伺服器)

初始協商要求伺服器身分識別驗證,而不是用戶端驗證

身分識別驗證(用戶端)

完整性

是,使用共用安全上下文

保密性

是,使用共用安全上下文

傳輸

HTTP

服務

下面的代碼和配置應獨立運行。執行下列操作之一:

  • 使用代碼(而不使用配置)建立獨立服務。
  • 使用提供的配置建立服務,但不定義任何終結點。
代碼

下面的代碼示範如何建立使用訊息安全的服務端點。

配置

以下配置可代替代碼使用。服務行為元素用於指定用來向用戶端驗證服務身份的認證。服務元素必須使用 behaviorConfiguration 屬性指定行為。繫結元素指定用戶端憑據類型為 None,這將允許匿名用戶端使用該服務。

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.serviceModel>    <behaviors>      <serviceBehaviors>        <behavior name="ServiceCredentialsBehavior">          <serviceCredentials>            <serviceCertificate findValue="contoso.com"                                 storeLocation="LocalMachine"                                storeName="My" />          </serviceCredentials>        </behavior>      </serviceBehaviors>    </behaviors>    <services>      <service behaviorConfiguration="ServiceCredentialsBehavior"                name="ServiceModel.Calculator">        <endpoint address="http://localhost/Calculator"                   binding="wsHttpBinding"                  bindingConfiguration="WSHttpBinding_ICalculator"                   name="CalculatorService"                  contract="ServiceModel.ICalculator" />      </service>    </services>    <bindings>      <wsHttpBinding>        <binding name="WSHttpBinding_ICalculator" >          <security mode="Message">            <message clientCredentialType="None" />          </security>        </binding>      </wsHttpBinding>    </bindings>    <client />  </system.serviceModel></configuration>

用戶端

下面的代碼和配置應獨立運行。請執行下列操作之一:

  • 使用代碼(和用戶端代碼)建立獨立用戶端。
  • 建立不定義任何端點位址的用戶端。而使用將配置名稱作為參數的用戶端建構函式。例如:
代碼

下面的代碼建立用戶端的一個執行個體。綁定使用訊息模式安全,用戶端憑據類型設定為 None。

配置

下面的代碼將配置用戶端。

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.serviceModel>    <bindings>      <wsHttpBinding>        <binding name="WSHttpBinding_ICalculator" >          <security mode="Message">            <message clientCredentialType="None" />          </security>        </binding>      </wsHttpBinding>    </bindings>    <client>      <endpoint address="http://machineName/Calculator"        binding="wsHttpBinding"        bindingConfiguration="WSHttpBinding_ICalculator"         contract="ICalculator"        name="WSHttpBinding_ICalculator">        <identity>          <dns value="contoso.com" />        </identity>      </endpoint>    </client>  </system.serviceModel></configuration>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.