Click here to Skip to main content
13,289,653 members (57,309 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 25 Oct 2009

Using IIS for Creating Scalable Windows Services

, 25 Oct 2009
Rate this:
Please Sign up or sign in to vote.
This article discusses a mechanism for creating scalable Windows services using IIS.


Sometime back we had to develop a rather scalable enterprise level Windows service. Creating a simple service is a cakewalk, deploying it for scalability is not. This article walks through how we combined Windows service and IIS together for a really good scalable deployment.

IIS gives us a large number of features which allow scalability, for example:

  1. Usage of application pools and their recycling
  2. Out of box scale out and load balancing
  3. Features like when the IIS worker process is using too much memory, a new worker process starts up leading to better performance

I could go on, but the point is that IIS has better scalability features than Windows services, simple things like multithreading and partitioning of execution space is provided by default. With little effort, we can develop solutions which work harmoniously across a server farm.

The trouble is that an IIS feature works when requested using an HTTP post. If we combine the best from both these worlds, we get a really great solution. That is what we try to do in this article.

For learning about how IIS provides scalability, please go to this link.

Windows services essentially execute some business logic over and over again after every time interval. The solution keeps this recurring logic in the Windows service while the business logic should be in a web or WCF service. Now this service can be called from the Windows service to do the job.

The Architecture of the Solution


Windows Server executing the service - This is a very simple Windows service whose sole purpose is to call a web service or WCF service at periodic intervals.

Load balancer - This may be a hardware or software based load balancer whose job is to distribute the request.

Servers executing business logic - These are servers which expose the service as a web / WCF service. The code is written in these to ensure scalability, some examples can be if we want to process records in a database or files on a server then this business logic will lock on a few records/files so that other competing servers may participate in the task. These servers should also be designed in such a manner that if the previous request is not completed, then new requests should not interfere with the previous request.

Some Sample Code

This is a very simple example in which every minute, we request the latest document dropped in the folder to be processed.

Timer timer = null; 
protected override void OnStart(string[] args) 
    timer = new Timer(60 * 1000); 
    timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); 
    timer.Enabled = true; 

The OnStart event handler for the service is kicked in when the service starts. All we are doing is setting up our timer here.

When the timer is elapsed, we want to call the web service as in this code:

void timer_Elapsed(object sender, ElapsedEventArgs e) 
    ServiceReferenceProxy.ServiceSoapClient webServiceProxy = 
			new ServiceReferenceProxy.ServiceSoapClient(); 
    webServiceProxy.DoSomeTaskCompleted += 
	new EventHandler<AsyncCompletedEventArgs>(webServiceProxy_DoSomeTaskCompleted); 

It should be noted that to do this, we have used async operation on the web service method. This has been done so that if the task is not completed and the timer elapses again we get better scalability.

It should also be noted that we are not doing anything specific to get scalability on the Windows service end. The network load balancer will do it for us.

When the task of the web service is completed, we may choose to log or do some task this is done by the Completed event handler.

void webServiceProxy_DoSomeTaskCompleted(object sender, AsyncCompletedEventArgs e) 
    //Log Something 

Setting Up Scalability Options

This section points out some reference material out on the net for setting up scalability:


  • 25th October, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Architect Imfinity
India India
Hi I have been working on enterprise applications for last six years.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
JeremyRemington29-Oct-09 19:55
memberJeremyRemington29-Oct-09 19:55 
GeneralMy vote of 1 Pin
António Barroso25-Oct-09 12:50
memberAntónio Barroso25-Oct-09 12:50 
GeneralRe: My vote of 1 Pin
gaurav_verma_mca25-Oct-09 18:16
membergaurav_verma_mca25-Oct-09 18:16 
GeneralMy vote of 1 Pin
Ruchit S.25-Oct-09 7:53
memberRuchit S.25-Oct-09 7:53 
GeneralRe: My vote of 1 Pin
gaurav_verma_mca25-Oct-09 8:27
membergaurav_verma_mca25-Oct-09 8:27 
GeneralServers executing business logic. Pin
Paulo Zemek25-Oct-09 4:40
memberPaulo Zemek25-Oct-09 4:40 
GeneralRe: Servers executing business logic. Pin
gaurav_verma_mca25-Oct-09 4:49
membergaurav_verma_mca25-Oct-09 4:49 
GeneralRe: Servers executing business logic. Pin
Paulo Zemek26-Oct-09 5:26
memberPaulo Zemek26-Oct-09 5:26 
GeneralRe: Servers executing business logic. Pin
gaurav_verma_mca26-Oct-09 6:58
membergaurav_verma_mca26-Oct-09 6:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 25 Oct 2009
Article Copyright 2009 by gaurav_verma_mca
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid