Server code needs a process in which to run, and infrastructure that will ensure that it runs when it’s needed and shuts down when an administrator asks. While you could code these features yourself, Windows Server 2008 provides hosting options so you don’t have to.
One of the best hosting environments in Windows Server 2008 is IIS 7.0, with the Windows Process Activation Service (WAS). WAS is a feature of IIS that listens for incoming requests and checks to see if your code is already running in a worker process. If it’s not, the WAS launches a worker process (w3wp.exe) using credentials that you specify at installation time. It then loads your code and allows you to process the request. This feature services ASP.NET applications as well as WCF Web services, and supports listening on TCP sockets, HTTP endpoints, named pipes, or Message Queuing queues.
When you host your application in IIS, you also get the benefit of automatic process recycling. An administrator can start and stop your application (via the Application Pools folder or via script), but IIS can also monitor your application and recycle your process automatically if certain limits are reached, such as memory usage or number of requests.
If you want to write your own hosting code, you should consider writing a Windows service to get started. This allows an administrator to send you signals when your service should start, stop, pause, or resume, at which point you can decide how to proceed. You can then use whatever technique you like for loading the server code that you want to run. The System.ServiceProcess namespace has the classes you need to get started writing a service.
The Windows Service Control Manager (SCM) has been extended so that a service can be automatically started and stopped based on system events or triggers. If your service doesn’t need to run all of the time, you should leverage this feature to reduce the resources your service uses, at the same time reducing power consumption and increasing the overall stability of the server.
The Windows “Server Core” installation option provides a minimal environment for running certain server roles, which reduces maintenance and management requirements as well as the attack surface exposed by the server. The Server Core installation option coming in Windows Server 2008 R2 will introduce support for a subset of the .NET Framework, including ASP.NET. This means you can build applications (including Web applications) that support Server Core. To help you target this option, be sure to download the FxCop rules that warn when you use a feature not present in Server Core.
IIS hosting will continue to get better with the introduction of Windows Server “Dublin” technologies. “Dublin” is a set of IIS extensions that make it simpler to host WCF and WF applications, including features like message-based correlation and content-based message forwarding, with greater scalability and manageability. “Dublin” also paves the way for Microsoft’s upcoming modeling technologies code-named “Oslo.”