Friday, February 5, 2010

Applying GZIP Compression to WCF Services

Hi guys!

Tweaking the web application's performance
Improving the web application's performance is getting more and more important these days. Recently, I have researched the approaches to gzip(compress) your WCF Service responses, which reduces the responses size in common 5 to 1 ratio. This results in faster transfer of the responses and less bandwidth. For instance, if you had responses with size 30kb, they will become 6kb when compressed, without losing anything. Sounds great, doesn't it?

3 easy ways to enable GZIP compression on your WCF Service:
1. Using IIS7
In case you are using IIS7, enabling the GZIP compression for the server's responses comes on the fly:
As you see, using IIS7 to compress the WCF responses is easy and straight-forward, but not everyone is running IIS7 on their production servers. So, let's think of other options, not including the usage of IIS7.

2. Writing a custom message encoder
Fortunately, Microsoft have covered this case, too. You can use their WCF sample for Custom Message Encoder: and use it in your WCF Services. You have to read and understand the sample, then modify it for your needs.

3. Using Telerik RadCompression
In case, you are finding the Custom Message Encoder sample too complicated or you are trying to use your WCF Service with Silverlight(which currently supports only basic/binary bindings), the easiest way to compress the responses, without having hard time with making things work is using the Telerik's RadCompression: Using the RadCompression, you just define the RadCompression HttpModule in your WCF Service's web.config and it instantly starts working, even when communicating with Silverlight.

In conclusion
As I had to apply gzip compression for a WCF Service, communicating with a Silverlight Application (using a Custom Binary Encoding -, without using an IIS7, I had hard time trying to modify the Custom Message Encoder Sample to work in my case, so I went using the Telerik's RadCompression module, which is very fast and easy to setup.

Happy optimizing!


Anonymous said...

Why is there not a standard for web service compression in the same manner as there is a standard for web service encryption. It seems that if WS standards can describe the encryption a message is using in its content and then apply the encryption to the message then the WS standards should equally be able to describe the compression a message is using in its content and then apply the compression to its content.

reza said...

hi. thanks for the post. Can you plz provide some guideline about how to enable the compression on IIS7 ? will be a great help for me.