如何在自托管 RESTful WCF Web 服务中启用 GZip 压缩?
我有一个使用 .NET 4.0 用 C# 编写的 RESTful WCF Web 服务,我希望使用 GZip 或 deflate 来压缩响应。 (我可能也需要支持请求压缩,但这还不是必需的)。它将部署为 Windows 服务,即自托管 WCF 服务,因为 IIS 托管不是一个选项。
到目前为止,我的搜索还不够。大多数点击要么是在 IIS 中打开压缩,要么是为基于 SOAP 的服务编写自定义消息编码器,两者都不适合我的场景。
如果您有任何关于如何执行此操作的指示,我们将不胜感激!
I have a RESTful WCF web service written in C# using .NET 4.0, and I'd like the responses to be compressed using GZip or deflate. (I might need to support compression for requests too, but that is not yet a requirement). It will be deployed as a windows service, i.e. self-hosted WCF service, as IIS hosting is not an option.
My searches have so far come up short. Most hits are either for turning on compression in IIS or writing a custom message encoder for a SOAP based service, neither or which fit my scenario.
If you have any pointers for how to do this, it would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确实需要采用自定义编码器路线(代码示例位于 http:// msdn.microsoft.com/en-us/library/ms751458.aspx)如果您想在自托管方案中进行 GZip 压缩(在 4.5 上,似乎支持压缩)二进制编码,根据 MSDN WCF 论坛 上的公告,但是4.0 中不存在开箱即用的功能)。为什么自定义编码器不适合您的场景?
You really need to go for the custom encoder route (sample with code at http://msdn.microsoft.com/en-us/library/ms751458.aspx) if you want to do GZip compression in a self-hosted scenario (on 4.5 it looks like there is support for compression on the binary encoding, per the announcement at the MSDN WCF Forums, but it doesn't exist out-of-the-box for 4.0). Why doesn't the custom encoder work for your scenario?