Saturday, June 9, 2012

WCF Hosting

The service-host application is the program that holds the service that has the actual objects. This is the server if you like to call it that. 
WCF Hosting are three Types:
  1. Self-hosting in any managed .NET application
  2. Hosting in a Windows service
  3. Hosting in different versions of IIS
Windows Communication Foundation (WCF) Services can be hosted with Internet Information Services (IIS); with the new Windows Activation Service (WAS) installed with IIS 7.0; or with any managed application process including console, Windows Forms, Windows Presentation Foundation (WPF), or managed Windows service applications. Selecting the right hosting environment for your services is a choice driven largely by deployment requirements related to transport protocol and operating platform.

Hosting Environment Features
A .NET application requires a hosting Windows process. Inside that Windows process, you can host multiple .NET application domains. An application domain is the means for the .NET CLR to isolate the managed code from Windows. The CLR automatically creates one default application domain in each worker process where it is initialized in a process. The default application domain is not unloaded until the process in which it runs shuts down. The CLR controls the shutdown of the default application domain. In most hosts, no code is running inside the default application domain. Instead, hosts (or processes) create a new application domain so the application domain can be closed independently of the process. In a lot of applications, it is desirable that the client-side code and server-side code execute in different application domains. Often, these desires stem from reasons such as security and isolation.
The relationship between processes and application domains is similar to the relationship between applications and application domains and the WCF ServiceHost. Bellow image illustrates, every process has at least one application domain, and each application domain can host zero or more WCF ServiceHost instances. WCF requires at least an application domain hosted inside a Windows process.



To be able to determine which host is the most applicable host for your scenario, you should refer to your nonfunctional requirements. Typically, nonfunctional requirements state technical requirements for your application to ensure they meet the quality and maintainability of your application. For WCF applications, this comes down to the following topics:
  • Availability: When do you want to be able to reach your service?
  • Reliability: What happens when your service somehow breaks? How does this affect other consumers?
  • Manageability: Do you need easy access to information about what is happening on the host where WCF services live?
  • Versioning: Do you need to support older versions of the service? Do you know who is consuming your services?
  • Deployment: What is your deployment model? Are you installing through the Microsoft Installer process and Visual Studio deployment packages, or is xcopy sufficient?
  • State: Are your services stateless? Do you need sessions?
Based on these nonfunctional requirements, you can decide which host meets your needs. To help you with this choice, for the remaining part of this chapter you will look at the different hosting environments, including their advantages and disadvantages.
Note   The WCF programming model is agnostic to where it is running, so switching to a different host later is always possible and doesn't mean you have to change your service implementation. Typically, you'll start with a self-hosted scenario in a console application to test-drive and prototype your services.

No comments:

Post a Comment