gpt4 book ai didi

c# - 如何在 WCF 4.5 中使用 gzip 压缩

转载 作者:IT王子 更新时间:2023-10-29 04:43:47 25 4
gpt4 key购买 nike

WCF 4.5 支持 GZIP,无需第三方库或手写扩展。我通过 TCP 绑定(bind)让它工作,但找不到通过 HTTP 绑定(bind)让它工作的方法。我的 wcf - 服务在 Windows 服务中自行托管。

插件:我不允许使用 IIS;我无法切换到任何 WCF 替代品。

这适用于 gzip:

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

这是我目前用于 http:

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

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

但是,根据这个它应该工作:

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

最佳答案

根据要求,我复制了我的评论作为答案:

"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

关于c# - 如何在 WCF 4.5 中使用 gzip 压缩,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15680087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com