How to get gzip compression working in WCF 4.5

谁说我不能喝 提交于 2019-11-26 20:23:50

问题


WCF 4.5 supports GZIP without third party libraries or handwritten extensions. I got it working via TCP Binding, but cannot find a way to get it working via HTTP Binding. my wcf - Service is self hosted in a windows service.

Addon: i am not allowed to use IIS; i can't switch to any WCF replacement.

this works with gzip:

binding="customBinding" bindingConfiguration="tcpCompressionBinding" name="tcp" 

and this is what i currently use for http:

binding="basicHttpBinding" bindingConfiguration="httpBinding" name="http"

The documentation does not really help me: http://msdn.microsoft.com/en-us/library/dd456789.aspx.

But, according to this it should work:

Beginning with WCF 4.5 the WCF binary encoder adds support for compression. The type of compression is configured with the CompressionFormat property. Both the client and the service must configure the CompressionFormat property. Compression will work for HTTP, HTTPS, and TCP protocols. If a client specifies to use compression but the service does not support it a protocol exception is thrown indicating a protocol mismatch. For more information, see Choosing a Message Encoder


回答1:


As per request I copied my comment as answer:

"Since this property is only exposed on the binaryMessageEncodingBindingElement, you will need to create a custom binding like the following to use this feature:

<customBinding>
  <binding name="BinaryCompressionBinding"> 
    <binaryMessageEncoding compressionFormat="GZip"/> 
    <httpTransport /> 
  </binding>
</customBinding> 

and receive compressed messages and therefore the compressionFormat property must be configured on the binaryMessageEncoding element on both client and service. "Both the client and the service need to agree to send



来源:https://stackoverflow.com/questions/15680087/how-to-get-gzip-compression-working-in-wcf-4-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!