C# - web service tip - compression

So, I’ve learned alot about C# because one of my projects I chose to go with C#. Well, here’s a little background. We have a linux server that will host the web service (using NuSoap). Then I have a windows client which is developed on C#. One thing that I know is that the data going back and forth will get large (around couple KBs). So, I’ve been trying to figure out how to use compression.

NuSoap has built in compression by checking if the HTTP headers if it supports it. So, I need to modify the clients header to tell the server it can receive compressed data. Basically for each service that .NET creates by WSDL, you need to override the GetResponseStream and GetRequestStream function.

GetRequestStream is where you would modify the headers to accept gzip.

GetResponseStream is where the decompression takes place when the server sends the data over.

I won’t write any code here, but you can search on google for some sample code. Real easy too.

After doing this, I did some analysis. Original data -> ~7KB, compressed data -> ~800B (about 90% reduced). Original data -> ~5KB, compressed data -> ~800B (about 80% reduced).

Sure… I’m not sending data that is huge, but this is for a simple case, and for future features that are intense with data, this will help.

Leave a Reply

You must be logged in to post a comment.