如何获得gzip的COM pression在WCF工作4.5如何获得、工作、gzip、pression

2023-09-03 01:52:12 作者:试卷是一张微凉的遗书

WCF 4.5支持GZIP没有第三方库或手写扩展。 我得到了通过TCP它的工作结合,但不能找到一种方式来获得通过HTTP它的工作结合。 我的WCF - 服务是自托管在一个窗口服务

插件:我不允许使​​用IIS;我不能切换到任何WCF更换。

这个作品用gzip:

 绑定=customBindingbindingConfiguration =tcpCom pressionBindingNAME =TCP
 

这是我目前使用什么HTTP:

 绑定=basicHttpBinding的bindingConfiguration =htt​​pBindingNAME =HTTP
 

该文件并没有真正帮助我: http://msdn.microsoft.com/en-us/library/dd456789.aspx.

不过,根据这一点,应该工作:

  

与WCF 4.5的WCF二进制EN codeR期初增加了对COM pression支持。的玉米pression的类型配置与COM pressionFormat属性。客户端和服务必须配置COM pressionFormat属性。 COM pression将适用于HTTP,HTTPS和TCP协议。如果客户端指定要使用的COM pression但服务不支持它的协议异常被抛出指示协议不匹配。欲了解更多信息,请参阅选择一个信息恩codeR

解决方案

根据要求,我复制我的评论,因为答案是:

  

由于此属性仅暴露在   binaryMessageEncodingBindingElement,你需要创建一个自定义   像下面绑定才能使用此功能:

 < customBinding>
  <绑定名称=BinaryCom pressionBinding>
    < binaryMessageEncoding COM pressionFormat =GZip压缩/>
    < httpTransport />
  < /装订>
< / customBinding>
 
IIS FastCGI PHP5.3 MySQL5.1 Gzip详细教程

  

和接收COM pressed消息,因此在COM pressionFormat   属性必须在binaryMessageEncoding元件上配置   客户端和服务。 无论是客户端和服务必须同意发送

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

解决方案

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