1

I'm writing an application using Visual Studio 2010 that needs to communicate with a remote web service. Because the amount of data being submitted is potentially large, (up to 100MB), the service's documentation says that the request message must be sent using GZIP HTTP compression.

My question is how to do that, given that I'm just calling a method on the proxy object that Visual Studio generated, and not actually performing the POST myself? In other words, since there isn't a "request" anywhere in my code to GZIP, how can I tell WCF to do it for me?

I've connected to the service by adding a service reference to my application using the WSDL provided, then invoking a method on the Visual Studio generated proxy to submit the request. An exception is thrown with the message "Request message must be sent using HTTP compression." (This is not unexpected, of course.)

enter image description here

Is there an attribute within the web.config settings that define the WCF service that will cause WCF to GZIP the request before sending it to the remote host?

Note: I've spent significant time searching the web about this, but the problem is that most posts assume that it's the web service's response that needs to be compressed. In my case, however, it's the request that's being sent from my client.

JeffK
  • 3,019
  • 2
  • 26
  • 29
  • did you able to resolve this issue? I am facing same issue, can you please help me? – M005 Jan 30 '16 at 10:13
  • No, but I moved on to another option that doesn't have this technical requirement, but requires a lot of manual record keeping. (For those in the know, this means we're using the IRS' UI option instead of the A2A interface.) – JeffK Apr 01 '16 at 01:32

2 Answers2

1

It seems like I have been able resolve this issue in a way that makes no sense to me from a "why does this even exist" way.

First, I was working on the same task as you: trying to use proxy objects to create a web request, and ended up running into the same issue being unable to compress the client object.

The resolution I ended up with was manually creating an XDocument object (XmlDocument would work as well) which has the same structure as the required SOAP XML, and then used the (already) populated proxy object to populate the necessary XML values in the string of SOAP XML.

From there I made a HttpWebRequest object and added the appropriate headers to the request. One of the headers was for compression. Executing the code resulted in getting an entirely different, non-compression related, error.

You can see my solution for the HttpWebRequest here: Compress a HttpWebRequest using gzip

It seems silly that it isn't easy to do through this the proxy object; however, it may be that the third-party did not expose what is necessary in order to add properties to the request header and either a.) they don't know or b.) they don't care, but that's what we have to work with, unfortunately.

I had to figure something out as I am on a deadline, but I hope this helps you out as well.

Community
  • 1
  • 1
Russ
  • 678
  • 8
  • 26
  • There is sample code for the `HttpWebRequest` object in the link provided. – Russ Feb 01 '16 at 18:23
  • I am getting "Invalid GZIP compressed request" error, can you please tell me what action I need to take? – M005 Feb 02 '16 at 10:38
  • Unfortunately, I'm not sure since I didn't encounter that error. If I were to venture a guess, it sounds like maybe you're trying to compress an object that cannot be compressed. – Russ Feb 02 '16 at 16:36
0

Have you tried adding <binaryMessageEncoding /> to the <customBinding /> element? I think we are working on similar tasks and I am also receiving the above FaultException. Two other SO topics led me down asking this question. It's something that makes sense, as I'm also not making a WebRequest through the code, but calling the service through the Service Reference created when I imported the WSDL provided by the third-party.

WCF custom binding for compression (a code-based approach)
and
WCF client endpoint compression (a configuration-based approach)

Let me know if you have any success with the above approaches.

Edit
An answer in the following thread indicates that unless you have control over the web service and the client, it might be something that can be done.

Using compression with C# webservice client in Visual Studio 2010

Edit #2
I think a few folks have been able to make progress in compressing a third-party service request using GZip. Please check out this post: Getting error for content mismtach while consuming client web service.

That post helped me get rid of the error message I was receiving (which was telling me that the request must be made using HTTP compression). I hope it helps you as well.

The request message must be sent using HTTP compression (RFC 1952 - GZIP).

Community
  • 1
  • 1
Russ
  • 678
  • 8
  • 26