HI END


一种永不妥协,追求极致与完美的精神与态度。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

Posted on 2013-03-13 10:43  HI END  阅读(257)  评论(0编辑  收藏  举报

来源:http://www.cnblogs.com/stangray/archive/2010/03/22/1691473.html

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

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

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

 

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

下载压缩类:GZipEncoder.rar