2

I have a WCF Data Service, and I am trying to enable support for IIS compression. So far the best I have got is when I tried the following:

static ServiceReference1.myTestEntities GetEntities()
{
    var content = new ServiceReference1.myTestEntities(new Uri(SERVICE_URL);
    content.IgnoreMissingProperties = true;
    content.SendingRequest += new EventHandler<System.Data.Services.Client.SendingRequestEventArgs>(content_SendingRequest);
    content.Credentials = System.Net.CredentialCache.DefaultCredentials;
    return content;
}

static void content_SendingRequest(object sender, System.Data.Services.Client.SendingRequestEventArgs e)
{
    foreach (var key in e.RequestHeaders.AllKeys)
    {
        if (string.Equals(key, "Accept-Encoding", StringComparison.InvariantCultureIgnoreCase))
        {
            return;
        }
    }
    e.RequestHeaders.Add("Accept-Encoding", "gzip,deflate,sdch");
}

The problem is that while it does add the accept-encoding header, the client doesn't decompress the reply it so it complains with errors like "hexadecimal value 0x1F is an invalid character. Line 1, position 1." which basically means that the client isn't decompressing the returned stream.

My ServiceReference1 was created just using "Add Service Reference" in Visual Studio 2010. Compression is working on my server as tested using a browser to the same request url and checking with Wireshark.

There doesn't seem to be any setting on the client proxy that I can find. So from this my question is, how can I enable WCF Data Service Compression for the client proxy?

Edit: Ideally i'm looking for something like this (which is for Windows Phone 7.5), but I want it for normal desktop applications.

Seph
  • 8,472
  • 10
  • 63
  • 94

0 Answers0