博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

WCF 提高传输数据性能方法之一 (使用压缩)

Posted on 2011-06-18 15:19  codingsilence  阅读(847)  评论(0编辑  收藏  举报

在WCF中使用Gzip压缩的配置方法

这是一种基于WCF通道传输数据的压缩技术,只要通过配置就可以在自己的项目中使用压缩技术,比较方便!

01 服务端App.config
02 <system.serviceModel>
03 <services>
04   <service behaviorConfiguration="metadataBehavior" name="WcfTest.Services.SwfBuilderService">
05     <endpoint address="http://127.0.0.1:99/swfbuild" binding="customBinding" bindingConfiguration="BufferedHttpSampleServer" bindingName="BufferedHttpSampleServer" contract="WcfTest.Contracts.ISwfBuilder" />
06   </service>
07 </services>
08 <extensions>
09   <bindingElementExtensions>
10     <add name="gzipMessageEncoding" type="GZipEncoder.GZipMessageEncodingElement, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
11   </bindingElementExtensions>
12 </extensions>
13 <bindings>
14   <customBinding>
15     <binding name="BufferedHttpSampleServer">
16       <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" />
17       <httpTransport hostNameComparisonMode="StrongWildcard"
18                      manualAddressing="False"
19                      maxReceivedMessageSize="65536"
20                      authenticationScheme="Anonymous"
21                      bypassProxyOnLocal="False"
22                      realm=""
23                      useDefaultWebProxy="True" />
24     </binding>
25   </customBinding>
26 </bindings>
27 <system.serviceModel>

 

01 客户端App.config
02 <system.serviceModel>
03 <bindings>
04   <customBinding>
05     <binding name="WSHttpBinding_SwfBuilderService">
06       <gzipMessageEncoding innerMessageEncoding="textMessageEncoding" />
07       <httpTransport manualAddressing="false"
08                      authenticationScheme="Anonymous"
09                      bypassProxyOnLocal="false"
10                      hostNameComparisonMode="StrongWildcard"
11                      proxyAuthenticationScheme="Anonymous"
12                      realm=""
13                      useDefaultWebProxy="true" />
14     </binding>
15   </customBinding>
16 </bindings>
17 </system.serviceModel>
18 <extensions>
19   <bindingElementExtensions>
20     <add name="gzipMessageEncoding" type="GZipEncoder.GZipMessageEncodingElement, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
21   </bindingElementExtensions>
22 </extensions>
23 <client>
24     <endpoint address="http://127.0.0.1:99/swfbuild" binding="customBinding"
25         bindingConfiguration="WSHttpBinding_SwfBuilderService" contract="SwfBuild.SwfBuilderService"
26         name="WSHttpBinding_SwfBuilderService">
27     </endpoint>
28   <metadata>
29     <policyImporters>
30       <extension type="GZipEncoder.GZipMessageEncodingBindingElementImporter, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
31     </policyImporters>
32   </metadata>
33 </client>