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

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

<p>I did find this <a href="http://www.vistax64.com/indigo/113763-wcf-client-j2ee-server-using-gzip.html" rel="noreferrer">link</a> but it sure seems a bit complex for functionality that should be handled out-of-the-box IMHO.</p>

<p>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:</p>

<ol>
<li><p>Dynamic Compression on IIS7 <strong>was</strong> 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!!</p></li>
<li><p>The other problem with the System.IO.Compression solution is that System.IO.Compression does not exist in the Silverlight CLR.</p></li>
</ol>

<p>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.</p>

[{'answer_id': 10040, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 4, 'selected': False, 'text': '<p>I didn\'t see a native way for WCF to do compression when doing a WCF project recently. I just used the System.IO.Compression namespace and made a quick compressor. Here\'s the code i used</p>\n\n<pre><code>public static class CompressedSerializer\n{\n    /// &lt;summary&gt;\n    /// Decompresses the specified compressed data.\n    /// &lt;/summary&gt;\n    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;\n    /// &lt;param name="compressedData"&gt;The compressed data.&lt;/param&gt;\n    /// &lt;returns&gt;&lt;/returns&gt;\n    public static T Decompress&lt;T&gt;(byte[] compressedData) where T : class\n    {\n        T result = null;\n        using (MemoryStream memory = new MemoryStream())\n        {\n            memory.Write(compressedData, 0, compressedData.Length);\n            memory.Position = 0L;\n\n            using (GZipStream zip= new GZipStream(memory, CompressionMode.Decompress, true))\n            {\n                zip.Flush();\n                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();\n                result = formatter.Deserialize(zip) as T;\n            }\n        }\n\n        return result;\n    }\n\n    /// &lt;summary&gt;\n    /// Compresses the specified data.\n    /// &lt;/summary&gt;\n    /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt;\n    /// &lt;param name="data"&gt;The data.&lt;/param&gt;\n    /// &lt;returns&gt;&lt;/returns&gt;\n    public static byte[] Compress&lt;T&gt;(T data)\n    {\n        byte[] result = null;\n        using (MemoryStream memory = new MemoryStream())\n        {\n            using (GZipStream zip= new GZipStream(memory, CompressionMode.Compress, true))\n            {\n                var formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();\n                formatter.Serialize(zip, data);\n            }\n\n            result = memory.ToArray();\n        }\n\n        return result;\n    }\n}\n</code></pre>\n\n<p>then i just had my services take in a byte array as an input, like such</p>\n\n<pre><code>void ReceiveData(byte[] data);\n</code></pre>\n\n<p>Worked out well for me. </p>\n'}, {'answer_id': 10162, 'author': 'Lance Fisher', 'author_id': 571, 'author_profile': 'https://Stackoverflow.com/users/571', 'pm_score': 4, 'selected': True, 'text': '<p>If you are using IIS7, take a look at the <a href="http://blogs.iis.net/ksingla/archive/2006/06/13/changes-to-compression-in-iis7.aspx" rel="noreferrer">Compression Module</a>.  This allows you to configure compression for HTTP requests to your server.</p>\n'}, {'answer_id': 434208, 'author': 'Daniel Ballinger', 'author_id': 54026, 'author_profile': 'https://Stackoverflow.com/users/54026', 'pm_score': 4, 'selected': False, 'text': '<p>WS-Compression for WCF allows you to configure compression on the binding.</p>\n\n<p>See <a href="http://weblogs.asp.net/cibrax/WS_2D00_Compression-for-WCF" rel="nofollow noreferrer">WS-Compression for WCF</a> by Pablo M. Cibraro</p>\n\n<p>Alternatively, try Microsofts <a href="http://msdn.microsoft.com/en-us/library/cc138373.aspx" rel="nofollow noreferrer">GZip Encoder Sample</a> which "creates an encoder channel that uses the System.IO.Compression.GZipStream class to compress outgoing WCF messages"</p>\n'}, {'answer_id': 3055643, 'author': 'Mike H.', 'author_id': 368495, 'author_profile': 'https://Stackoverflow.com/users/368495', 'pm_score': 2, 'selected': False, 'text': '<p>It should also be noted that you may need to add the mime type to <code>applicationHost.config</code> under <code>&lt;httpCompression&gt;&lt;dynamicTypes&gt;</code> section in addition to enabling compression for the site:</p>\n\n<pre><code>&lt;add mimeType="application/soap+msbin1" enabled="true" /&gt;\n</code></pre>\n\n<p>If certain dynamic responses are not being compressed (and some are) it could be a mime type issue.  Use Fiddler to get the specifics associated with the request.  Failed request tracing may be useful in determining whether or not IIS is even attempting to compression the response.  If compression is correctly configured you will see a <code>NO_MATCHING_CONTENT_TYPE</code> in the <strong>complete trace</strong> section of the trace output.</p>\n'}]
['https://Stackoverflow.com/questions/10006', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/313/']