views:

335

answers:

2

I have to interface with a slightly archaic system that doesn't use webservices. In order to send data to this system, I need to post an XML document into a form on the other system's website. This XML document can get very large so I would like to compress it. The other system sits on IIS and I use C# my end. I could of course implement something that compresses the data before posting it, but that requires the other system to change so it can decompress the data. I would like to avoid changing the other system as I don't own it.

I have heard vague things about enabling compression / http 1.1 in IIS and the browser but I have no idea how to translate that to my program. Basically, is there some property I can set in my program that will make my program automatically compress the data that it is sending to IIS and for IIS to seamlessly decompress it so the receiving app doesn't even know the difference?

Here is some sample code to show roughly what I am doing;

private static void demo()
    {

        Stream myRequestStream = null;
        Stream myResponseStream = null;

        HttpWebRequest myWebRequest = (HttpWebRequest)System.Net
                              .WebRequest.Create("http://example.com");
        byte[] bytMessage = null;
        bytMessage = Encoding.ASCII.GetBytes("data=xyz");
        myWebRequest.ContentLength = bytMessage.Length;
        myWebRequest.Method = "POST";

        // Set the content type as form so that the data
        // will be posted as form              
        myWebRequest.ContentType = "application/x-www-form-urlencoded";

        //Get Stream object 
        myRequestStream = myWebRequest.GetRequestStream();

        //Writes a sequence of bytes to the current stream    
        myRequestStream.Write(bytMessage, 0, bytMessage.Length);

        //Close stream
        myRequestStream.Close();

        WebResponse myWebResponse = myWebRequest.GetResponse();
        myResponseStream = myWebResponse.GetResponseStream();
}

"data=xyz" will actually be "data=[a several MB XML document]".

I am aware that this question may ultimately fall under the non-programming banner if this is achievable through non-programmatic means so apologies in advance.

+2  A: 

I see no way to compress the data on one side and receiving them uncompressed on the other side without actively uncompressing the data..

VVS
A: 

No idea if this will work since all of the examples I could find were for download, but you could try using gzip to compress the data, then set the Content-Encoding header on the outgoing message to gzip. I believe that the Length should be the length of the zipped message, although you may want to play with making it the length of the unencoded message if that doesn't work.

Good luck.

EDIT I think the issue is whether the ISAPI filter that supports compression is ever/always/configurably invoked on upload. I couldn't find an answer to that so I suspect that the answer is never, but you won't know until you try (or find the answer that eluded me).

tvanfosson