We have a data service provider that is providing us with Dynamic Compression on a WCF Data Services site. We need to make use of that compression because the raw data that we are pulling is more than 5Gb daily. Using gzip that will fall dramatically.
We have a client application which was created using the “Add service reference” wizard in Visual Studio 2010 which is based on the DataServiceContext class. I am able to specify the Accept: gzip, deflate header using the SendingRequest event, but how can I get the deserializer to decode the stream before it tries to parse the XML?
I couldn’t figure out how to do this with the provided framework tools so I had to roll my own. First is the method that does the actual request that shows how to specify the header that requests
gzipencoding and unzips the result.The DynamicJson library is an open-source library that I wrote a while ago which came in very handy here. You can very easily leave out the
Accept: application/jsonheader and then you will get back XML. In this case, something likelinq-to-xmlwill also work, in very much the same way.Next the client code. This shows how to construct the URL to pass to the
MakeHttpQuerymethod also what to do with the result.