程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> 關於.NET >> WCF NetTcpBinding Transport安全模式(3)

WCF NetTcpBinding Transport安全模式(3)

編輯:關於.NET

ProtectionLevel設置保護級別

書接上文,是哪一項配置使得WCF對傳輸的消息進行加密操作了呢?繼續修改 配置文件,客戶端配置文件如代碼清單11-18所示,服務端配置文件如代碼清單 11-19所示。

代碼清單11-18  修改客戶端的protectionLevel

<?xml version="1.0" encoding="utf-8" ?>
    
<configuration>
    
  <system.serviceModel>
    
    <behaviors >
    
      <endpointBehaviors>
    
        <behavior  name="ForListen">
    
          <clientVia viaUri="net.tcp://127.0.0.1:64590/HelloService"/>
    
        </behavior>
    
      </endpointBehaviors>
    
    </behaviors>
    
    <bindings>
    
<netTcpBinding>
    
        <binding name="tcpWindowsSecurity">
    
          <security mode="Transport" >
    
    <transport protectionLevel="None"></transport>
    
          </security>
    
        </binding>
    
      </netTcpBinding>
    
    </bindings>
    
    <client>
    
      <endpoint name="helloEndPoint" 

address="net.tcp://127.0.0.1:64567/HelloService"
    
          binding="netTcpBinding" 

bindingConfiguration="tcpWindowsSecurity"
    
          

contract="WcfSecurityExampleServiceLibrary.IHelloService" 

behaviorConfiguration="ForListen" />
    
    </client>
    
  </system.serviceModel>
    
     
    
</configuration>

代碼清單11-19    修改服務端端的protectionLevel

<?xml version="1.0"?>
    
<configuration>
    
     
    
  <system.serviceModel>
    
    <services>
    
      <service 

name="WcfSecurityExampleServiceLibrary.HelloService" 

behaviorConfiguration="mex">
    
        <host>
    
          <baseAddresses>
    
            <add 

baseAddress="net.tcp://127.0.0.1:64567/"/>
    
          </baseAddresses>
    
        </host>
    
        <endpoint 

address="net.tcp://127.0.0.1:64567/HelloService" 

binding="netTcpBinding"
    
                  bindingConfiguration="tcpWindowsSecurity" 

name="helloEndPoint"
    
                  

contract="WcfSecurityExampleServiceLibrary.IHelloService"/>

;
    
       
    
     
    
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
    
      </service>
    
    </services>
    
    <bindings>
    
     
    
      <netTcpBinding>
    
        <binding name="tcpWindowsSecurity">
    
         <security mode="Transport" >
    
    <transport 

protectionLevel="None"></transport>
    
         </security> 
    
        </binding>
    
      </netTcpBinding>
    
    </bindings>
    
     
    
    <behaviors>
    
      <serviceBehaviors>
    
        <behavior name="mex">
    
          <serviceMetadata  />
    
        </behavior>
    
      </serviceBehaviors>
    
    </behaviors>
    
  </system.serviceModel>
    
     
    
  <startup>
    
    <supportedRuntime version="v4.0" 

sku=".NETFramework,Version=v4.0"/>
    
  </startup>
    
</configuration>

通過以上兩段代碼,Transport安全模式下的protectionLevel設置為None。此 時運行結果和TcpTrace的結果如圖11-8所示。

查看本欄目

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved