在 Silverlight 中向 WCF 添加压缩的最简单方法是什么? [英] What is the easiest way to add compression to WCF in Silverlight?

查看:25
本文介绍了在 Silverlight 中向 WCF 添加压缩的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于访问 WCF Web 服务的 Silverlight 2 beta 2 应用程序.正因为如此,它目前只能使用 basicHttp 绑定.Web 服务将返回相当大量的 XML 数据.从带宽使用的角度来看,这似乎相当浪费,因为如果压缩,响应会小 5 倍(我实际上将响应粘贴到 txt 文件中并压缩它.).

I have a silverlight 2 beta 2 application that accesses a WCF web service. Because of this, it currently can only use basicHttp binding. The webservice will return fairly large amounts of XML data. This seems fairly wasteful from a bandwidth usage standpoint as the response, if zipped, would be smaller by a factor of 5 (I actually pasted the response into a txt file and zipped it.).

请求确实有Accept-Encoding: gzip, deflate" - 有没有办法让 WCF 服务 gzip(或以其他方式压缩)响应?

The request does have the "Accept-Encoding: gzip, deflate" - Is there any way have the WCF service gzip (or otherwise compress) the response?

我确实找到了这个链接 但对于应该立即处理的功能来说,这确实有点复杂,恕我直言.

I did find this link but it sure seems a bit complex for functionality that should be handled out-of-the-box IMHO.

好的 - 起初我使用 System.IO.Compression 将解决方案标记为答案,因为我永远无法似乎"让 IIS7 动态压缩工作.好吧,事实证明:

OK - at first I marked the solution using the System.IO.Compression as the answer as I could never "seem" to get the IIS7 dynamic compression to work. Well, as it turns out:

  1. IIS7 上的动态压缩 一直在工作.只是 Nikhil 的用于 IE 的 Web Developer Helper 插件没有显示它可以工作.我的猜测是,由于 SL 将 Web 服务调用交给浏览器,浏览器会在幕后"处理它,而 Nikhil 的工具永远不会看到压缩的响应.我能够通过使用 Fiddler 来确认这一点,该 Fiddler 监控浏览器应用程序外部的流量.在 fiddler 中,响应实际上是 gzip 压缩的!!

  1. Dynamic Compression on IIS7 was working al along. It is just that Nikhil's Web Developer Helper plugin for IE did not show it working. My guess is that since SL hands the web service call off to the browser, that the browser handles it "under the covers" and Nikhil's tool never sees the compressed response. I was able to confirm this by using Fiddler which monitors traffic external to the browser application. In fiddler, the response was, in fact, gzip compressed!!

System.IO.Compression 解决方案的另一个问题是 Silverlight CLR 中不存在 System.IO.Compression.

The other problem with the System.IO.Compression solution is that System.IO.Compression does not exist in the Silverlight CLR.

所以从我的角度来看,在 Silverlight 中启用 WCF 压缩的最简单方法是在 IIS7 中启用动态压缩并且根本不编写代码.

So from my perspective, the EASIEST way to enable WCF compression in Silverlight is to enable Dynamic Compression in IIS7 and write no code at all.

推荐答案

如果您使用的是 IIS7,请查看 压缩模块.这允许您为服务器的 HTTP 请求配置压缩.

If you are using IIS7, take a look at the Compression Module. This allows you to configure compression for HTTP requests to your server.

这篇关于在 Silverlight 中向 WCF 添加压缩的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆