WCF常用安全方案(一)

來源:互聯網
上載者:User

不安全的 Internet 用戶端和服務

下面的插圖示範了一個公用的、不安全的 Windows Communication Foundation (WCF) 用戶端和服務的樣本。


特徵 說明

安全模式

傳輸

HTTP

綁定

在代碼中使用 BasicHttpBinding,或在配置中使用 <basicHttpBinding> 元素。

互通性

與現有的 Web 服務用戶端和服務進行互操作

身分識別驗證

None

完整性

None

保密性

None

服務

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

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

下面的代碼示範如何建立不安全的終結點。預設情況下,BasicHttpBinding 將安全模式設定為 None。

服務配置

下面的代碼使用配置設定相同的終結點。

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.serviceModel>    <behaviors />    <services>      <service behaviorConfiguration="" name="ServiceModel.Calculator">        <endpoint address="http://localhost/Calculator"                   binding="basicHttpBinding"                  bindingConfiguration="Basic_Unsecured"                   name="BasicHttp_ICalculator"                  contract="ServiceModel.ICalculator" />      </service>    </services>    <bindings>      <basicHttpBinding>        <binding name="Basic_Unsecured" />      </basicHttpBinding>    </bindings>    <client />  </system.serviceModel></configuration>

用戶端

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

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

下面的代碼示範一個訪問不安全終結點的基本 WCF 用戶端。

用戶端配置

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

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.serviceModel>    <bindings>      <basicHttpBinding>        <binding name="BasicHttpBinding_ICalculator" >          <security mode="None">          </security>        </binding>      </basicHttpBinding>    </bindings>    <client>      <endpoint address="http://localhost/Calculator/Unsecured"          binding="basicHttpBinding"           bindingConfiguration="BasicHttpBinding_ICalculator"          contract="ICalculator"           name="BasicHttpBinding_ICalculator" />    </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.