Thursday, July 31, 2014

Using Rashan’s WCF Compression Library

In one of my previous posts, I have discussed the general idea of compressing the traffic of a WCF service and how I started implementing a reusable component to achieve this. In this post, let us see how easy to enable compression in any WCF service by using my reusable library, without changing any code of an existing implementation!

Installing the component

The compression library should be installed on both the WCF service hosting project and the client project, that consumes the service. This can be done easily by using Nuget.
  • If the Nuget package console is used, then execute the following command for each project (i.e. service and Clients).
PM> Install-Package Rashans.WCF.Compression
  • If the Nuget GUI is used, then search for “wcf compression encoder” and select the package with Id Rashans.WCF.Compression.

Tuesday, July 29, 2014

Improving the performance of a WCF service

Recently I was tasked to look into certain performance issues of a large Enterprise application having a service oriented architecture. The front end web site is based on Microsoft ASP.Net MVC and the entire business logic layer of the application is implemented as a series of WCF web services that are primarily exposed over TCP (i.e. using net.tcp binding). In order to increase the scalability of the system, each tier of the application deployed in separate servers. After spending some time improving the web front end, I quickly realized that the primary reason for intermittent slowness of the application is due to the fact that a large amount of data passing between the service layer and the web layer (i.e. web server and application server). If we are to improve this situation, then we have either to improve the network infrastructure or reduce the amount of data. Since, upgrading the network connectivity was not an option, I was focusing my effort on the later. As a result, I was investigating the possibility of compressing the traffic between the web server and application server.

How to enable compression on WCF traffic?

As it turns out, enabling compression is not trivial in WCF services. However, if your services are hosted in IIS, then you will be able to utilize the built-in compression module for certain message types. [UPDATE: Since, .net v4.5, you can actually enable compression for binary message encoder] Fortunately, I found a wonderful sample on MSDN where data compression is achieved via a custom message encoder. After going through the sample implementation, I decided to implement a reusable component where I can enable compression for both binary and text message encoders with the extra option of able to decide the compression algorithm (Gzip, Bzip2, Deflate, etc…). I created a Nuget package of my initial implementation and now it is available on I will explain more on using this package in a future article and I hope it will be useful for others as well.

Technorati Tags: ,,,