Net.WebClient and GZip

The Net.WebClient class doesn't support HTTP compression, eg, when you add the Accept-Encoding: gzip,deflate header to your request:


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2004/08/netwebclient-and-gzip.html

Of course in the REAL world, before un-gzipping, you’d actually check to make sure the response header contained the

Content-Encoding: gzip

header indicating the byte array you got was actually compressed… right? right?

How about web services? Could they also be encoded with gzip?

Definitely! For example…

http://www.codeproject.com/cs/webservices/WebServiceZipFilter.asp

also…

Retrieving Data from Web Services using Standard HTTP 1.1 Compression

http://www.dotnetjunkies.com/Tutorial/90D3B3E0-6544-4594-B3BA-E41D8F381324.dcik

BEWARE! The SharpLipZip does not seem to properly support “deflate” type compression. At least I can’t find any references in Google to anyone who actually GOT it to work… fortunately this type of compression is rare. But still, I’d modify…

wc.Headers.Add(“Accept-Encoding”, “gzip,deflate”)

to be just

wc.Headers.Add(“Accept-Encoding”, “gzip”)

and prevent any future problems.

See my updated blog entry on this:

http://www.codinghorror.com/blog/archives/000182.html

For webservices, assuming compression is enabled on the server side, all you have to do is set the EnableDecompression property to true on your proxy class generated with the wsdl tool.

In fact the .NET 2.0 docs clearly states EnableDecompression is set to true by default so all you need is to make the server send it gzip compressed.

Look it up in the docs or google on “EnableDecompression”.

We are using ICSharpCode in Sitemap Writer Pro for compression of big sitemap files.
http://www.sitemapwriter.com