WCF常用安全方案(二)

來源:互聯網
上載者:User

不安全的 Intranet 用戶端和服務

下面的插圖描述了一種簡單的 Windows Communication Foundation (WCF) 服務,開發此服務的目的是為了向 WCF 應用程式提供有關安全專用網路的資訊。在以下情況下無需提供安全性:資料重要性較低、網路在本質上是安全的,或者由 WCF 基礎結構的下層提供安全性。


特徵 說明

安全模式

傳輸

TCP

綁定

NetTcpBinding

互通性

僅 WCF

身分識別驗證

None

完整性

None

保密性

None

服務

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

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

下面的代碼示範如何建立不安全的終結點:

配置

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

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.serviceModel>    <behaviors />    <services>      <service behaviorConfiguration=""                name="ServiceModel.Calculator">        <endpoint address="net.tcp://localhost:8008/Calculator"                   binding="netTcpBinding"                  bindingConfiguration="tcp_Unsecured"                   name="netTcp_ICalculator"                  contract="ServiceModel.ICalculator" />      </service>    </services>    <bindings>      <netTcpBinding>        <binding name="tcp_Unsecured">          <security mode="None" />        </binding>      </netTcpBinding>    </bindings>    <client />  </system.serviceModel></configuration>

用戶端

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

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

以下代碼示範一個使用 TCP 協議訪問不安全終結點的基本 WCF 用戶端。

配置

下面的配置代碼應用於用戶端:

<?xml version="1.0" encoding="utf-8"?><configuration>  <system.serviceModel>    <bindings>      <netTcpBinding>        <binding name="NetTcpBinding_ICalculator" >          <security mode="None">          </security>        </binding>      </netTcpBinding>    </bindings>    <client>      <endpoint address="net.tcp://machineName:8008/Calculator "                binding="netTcpBinding"                 bindingConfiguration="NetTcpBinding_ICalculator"                contract="ICalculator"                 name="NetTcpBinding_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.