GZip compression in WCF WebService
c#, gzip, wcf, web-services
Solution
Solved!! The code in the question was enough for Service references. If you are using Web references, add also the line
my_service_object.EnableDecompression = true;
Problem
I have a .NET 3.5 Webservice Hosted on IIS7.5. I have a client application who connects to this webservice. I changed (in client application) the httpWebRequest.Create method to add automaticDecompression for GZip but it isn't working ``` WebRequest IWebRequestCreate.Create(Uri uri) { HttpWebRequest httpWebRequest = Activator.CreateInstance( typeof(HttpWebRequest), BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { uri, null }, null) as HttpWebRequest; if (httpWebRequest == null) return null; httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; return httpWebRequest; } ``` In this way the request is sent correctly, the answer is encoded in gzip (I see it from Fiddler), but an exception occurs: ``` Response is not wellformed XML ``` (I think the client doesn't decode the answer) If I remove this row, as in MSDN documentation ``` httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); ``` The answer is not GZip encoded (and in the request there's no ACCEPT-ENCODING header)