We have a web application hosted in a third-party hosting environment. The server application provides some WCF RESTFUL services for our iPad applications.
WCF services are .svc-less and are registered in the Glonbal.asax file. Example:
RouteTable.Routes.Add("service name", new ServiceRoute("url", new WebServiceHostFactory(), routingServiceContract));
Since we need to transfer some massive data from our iPad applications to the server application, some of them will be compressed by GZIP before sending to the WCF service. And since the server application was originally built on the basis of .NET 3.5, a piece of code like this was responsible for decompressing compressed requests:
public void Application_BeginRequest(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.Headers["Content-Encoding"])) { if (Request.Headers["Content-Encoding"].ToLower().Contains("gzip")) Request.Filter = new GZipStream(Request.Filter, CompressionMode.Decompress); if (Request.Headers["Content-Encoding"].ToLower().Contains("deflate")) Request.Filter = new DeflateStream(Request.Filter, CompressionMode.Decompress); } }
This worked until our hosting provider installed .NET 4.5 on their server. Then the compressed JSON requests started to crash (we get http 400 or sometimes 500 errors). After such a big investigation, it turned out that the code and the web.config file were fine, because the WCF service works fine on a server that does not have .NET 4.5 installed.
I even commented on the code above and posted it on the same server, but it did not work again. I thought the request was decoded twice!
Now I am wondering how can I use the built-in compression function of WCF 4.5 and make this website work? I prefer to get rid of custom C # code and just use the WCF 4.5 compression function.
ps the web service is in ASP.NET compatibility mode.
The pps web service works fine if we do not compress the HTTP request.