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:

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…


Retrieving Data from Web Services using Standard HTTP 1.1 Compression

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:

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.