What is the easiest way to add compression to WCF in Silverlight?

Posted by caryden on Stack Overflow See other posts from Stack Overflow or by caryden
Published on 2008-08-13T16:08:43Z Indexed on 2010/06/15 12:02 UTC
Read the original article Hit count: 251

Filed under:
|
|
|

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.).

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.

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. 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!!

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

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.

© Stack Overflow or respective owner

Related posts about wcf

Related posts about Silverlight