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所示。
查看本欄目