|
||||||||||||||
|
Message-Based Activation
One of the most important features IIS provides your WCF services is message-based activation. ServiceHost instances need not be open prior to processing requests for a given endpoint. Instead, the World Wide Web Publishing Service (WWW Service) is responsible for ensuring a worker process is present to handle requests. Then, when IIS forwards requests for a particular .svc endpoint to the worker process, the service model initializes the corresponding ServiceHost (if necessary), before dispatching the request through the channel stack.
There are many participants in this activation process:
This message-based activation process allows IIS to balance the number of worker processes required to service request loads, releasing unused resources where appropriate. IIS also monitors the health of each worker process and will launch a new, healthy worker process to service requests as needed. In addition, you can configure IIS to periodically recycle worker processes to reduce the risk of resource and memory leaks. These features improve the overall reliability and availability of your WCF services. ASP.NET Compatibility Mode Once you activate the ServiceHost, hosting a WCF service with IIS operates much the same as self-hosted services. That is, the service model has a consistent way of processing requests. The ASP.NET processing model is only involved as far as passing the request to the correct HTTP handler, the service model's HttpHandler type. In fact, the service model has two modes for hosting WCF services:
If you are porting existing ASP.NET Web services (ASMX), you may have existing code that relies on the HttpContext or other ASP.NET features. For example, you may want to access the ASP.NET Session, Cache, or Profile objects to provide a consistent run-time experience as you would have with ASMX. You can enable ASP.NET compatibility by setting the aspNetCompabitilityEnabled property to true in the <serviceHostingEnvironment> section:
This makes it possible for your service code, or its downstream objects, to interact with these aforementioned ASP.NET features. For example, you can write code that relies on the ASP.NET Profile. Consider this <profile> section in the web.config:
Your service code could access it as follows, using the current HttpContext:
Services can also require a hosting environment that supports ASP.NET compatibility by applying the AspNetCompatibilityRequirementsAttribute from the System.ServiceModel.Activation namespace.
Other than porting ASMX services, you will most likely avoid using this feature in order to provide a consistent hosting model for your services over multiple protocols.
|
||||||||||||||
|