This is our scenario (which is not negotiable):
- WCF REST service running over HTTP using WebHttpEndpoint hosted in IIS7
- All responses and POST request data transmitted as JSON
- Web Client without WCF
- We have activated gzip compression for JSON responses in IIS7, which works great.
Since we perform mail requests with large JSON payloads, we implemented client-side GZIP compression for post-Soviet JSON data and set the "Content-Encoding" header to "gzip". Unfortunately, IIS cannot handle this. Mail data reaches the WCF deserializer in a compressed form, which of course leads to an exception.
I tried different extension points to connect to the WCF pipeline, but the only promising solution (Operation Behavior) did not work, because in the absence of the WCF client, the ApplyClientBehavior of the IOperationBehavior interface will never be called.
In the end, if an HttpModule is implemented that does the job, but I'm not completely happy with the result due to the following reservations:
- Although I can transparently decompress request data by setting the filter property of the current HttpRequest to GZipInputStream, that is only half the solution, because WCF insists on reading exactly the HttpRequest.ContentLength byte from the request, which for compressed requests will obviously be much less than the uncompressed payload
- For some strange reason, besides my imagination, Microsoft has blocked every legitimate way to modify the ContentLength of a request. In the end, I had to change the private support field for the ContentLength property of the request. This is not what you want to do in production code.
- Microsoft was also unable to read the InputStream request in the HttpModule to determine the length of the uncompressed content, which required our web client to also pass its own header containing the length of the uncompressed content
All in all, this seems like a terrible job that cannot be implemented cleanly, so I would like to know if anyone can indicate alternatives for implementing the decompression part in IIS. I absolutely agree with the recommendations for a commercial product that does this, if any.
source share