4

We have a WCF REST service hosted on IIS 7 with .NET Framework 4.5. The client is sending data in GZip compressed format with request headers:

Content-Encoding:gzip
Content-Type: application/xml

But we are getting bad request from the server, if the request is in compressed format. We enabled Request compression by implementation of IHttpModule that will filter/modify incoming requests. From my understanding, this is failing because WCF uses original content length (that of compressed data) instead of Decompressed data. So here are my questions:

Is there any way we can fix this content length issues in IIS7/.NET 4.5? My HTTP module implementation is given below:

httpApplication.Request.Filter = New GZipStream(httpApplication.Request.Filter, CompressionMode.Decompress)`

If fixing the content length issue is not possible at server side, is there any way I can send original content length from client with a compressed request? Client side implementation is as follows:

using (Stream requeststream = serviceRequest.GetRequestStream())
{
   if (useCompression)
   {
       using (GZipStream zipStream = new GZipStream(requeststream, CompressionMode.Compress))
       {
           zipStream.Write(bytes, 0, bytes.Length);
           zipStream.Close();
           requeststream.Close();
       }

       serviceRequest.Headers.Add("Content-Encoding", "gzip");
   }
   else
   {
       requeststream.Write(bytes, 0, bytes.Length);
       requeststream.Close();
   }
}
tom redfern
  • 30,562
  • 14
  • 91
  • 126
neo
  • 6,131
  • 6
  • 22
  • 27
  • 1
    I have the same problem with our server giving a '400 bad request' when I send a compressed request. Did you ever find a solution for this? – ParvusM Aug 17 '17 at 07:40

1 Answers1

0

Check if this can work for you Compression and the Binary Encoder MSDN: Choosing a Message Encoder

hB0
  • 1,977
  • 1
  • 27
  • 33