WCF NetTcpBinding Transport安全模式(3)2014-06-26ProtectionLevel设置保护级别书接上文,是哪一项配置使得WCF对传输的消息进行加密操作了呢?继续修改 配置文件,客户端配置文件如代码清单11-18所示,服务端配置文件如代码清单 11-19所示。代码清单11-18 修改客户端的protectionLevel
<?xml version="1.0" encoding="utf-8" ?><configuration><system.serviceModel><behaviors ><endpointBehaviors><behaviorname="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>