With the help of this question and this post I’ve managed to get WebHttpBinding to work with compression (by means of copy-pasting the code). When pointing the browser to my service method, it downloads a file which I can rename to .zip and decompress, so the compression part works. But I’m not able to use Json instead of XML. When I add the webget attribute to the method I just get “[Fiddler] ReadResponse() failed: The server did not return a response for this request.”
Also the GZipMessageEncoder.WriteMessage isn’t even called. What do I need to change in order to get this working with Json ?
Thanks.
From the post on MSDN, you’d also need to override the
MessageEncoder.IsContentTypeSupportedto make sure that the gzip encoder also accepts JSON.The code below has the modified version of that code. I also added a message inspector to add a
Content-Encodingheader, which will allow the browsers to understand the data as-is.