A tentative approach to WCF -8:WCF service hosting (top)

Source: Internet
Author: User
Tags hosting

The operation of any program needs to rely on a deterministic process, and WCF services are no exception. If you use a WCF service, we must host the service in a runtime environment that creates it and controls its context and lifetime, which we call the host. WCF services can run in any Windows process that supports managed code. WCF provides a unified programming model for building service-oriented applications. This programming model remains consistent and independent of the runtime environment of the deployment service. In fact, this means that the code for the service looks very similar regardless of the hosting option.

These host options can be console applications or Windows services that run within a server environment (such as Internet Information Services (IIS) or Windows Process Activation Services (was) that are managed in a worker process. Developers can choose a hosting environment that meets the requirements for service deployment. These requirements may originate from the platform in which the application is deployed, the transmission of messages that must be sent and received, or the type of process recycling and other processes required to ensure sufficient availability, or some other management or reliability requirements.

WCF There are several main ways to host your environment:

    1. Self-hosted in managed applications

WCF services can be hosted in any managed application. This is the most flexible option because it requires the least infrastructure to deploy. Embed the service code within the managed application code, and then create and open an instance of ServiceHost to make the service available.

This option has two common scenarios: WCF services that run within a console application, and applications that are client applications, such as Windows Presentation Foundation (WPF) or Windows Forms (WinForms). In the development phase of an application, it is often useful to host a WCF service within a console application. This makes it easier to debug the service, tracking information from it to find out what is happening within the application, and making it easier to move back and forth by copying it to a new location. This host option also makes it easy for client applications, such as WPF and WinForms applications, to communicate with the outside world. For example, a peer collaboration client that uses WPF for its user interface and as a WCF service host allows other clients to connect to it and share information.

2. Managed Windows Services

This host option includes registering the WCF service as a managed Windows service (formerly known as NT Service) in which the application domain (AppDomain) is hosted so that the service's process lifetime is controlled by the Service Control Manager (SCM) of the Windows service. As with the self-hosted option, this type of hosting environment requires some host code to be written as part of the application. This service is implemented both as a Windows service and a WCF service by enabling the service to inherit from the ServiceBase class and from the WCF Service contract interface. Then create a ServiceHost, open it within the overridden OnStart (string[]) method and close it within the overridden OnStop () method. You must also implement an installer class that inherits from Installer to allow the Installutil.exe tool to install the program as a Windows service. In a secure environment where messages are not activated, scenarios that are enabled by the Managed Windows Service hosting option are scenarios for long-running WCF services that are hosted outside of IIS. The lifetime of the service is changed by the operating system control. This host option is available in all versions of Windows.

3. Internet Information Services (IIS)

IIS host options are integrated with ASP., and use the features provided by these technologies, such as process recycling, idle shutdown, process health monitoring, and message-based activation. On Windows XP and the Windows Server 2003 operating system, this is the preferred solution to host a highly available and highly scalable WEB Service application. IIS also provides the integration manageability that customers expect from enterprise-Class Server products. This host option requires that IIS be configured correctly, but you do not need to write any hosting code as part of the application.

Note that a service that is hosted on IIS can only use HTTP transport. Its implementation in IIS 5.1 introduces some restrictions in Windows XP. Message-based activation provided by IIS 5.1 for WCF services on Windows XP prevents any other self-hosted WCF services on the same computer from using port 80 for communication. When hosted in IIS 6.0 on Windows Server 2003, WCF Services can run in the same appdomain/application pool/worker process as other applications. However, because both WCF and IIS 6.0 use kernel-mode HTTP stacks (. sys), IIS 6.0 can share port 80 with other self-hosted WCF services that are running on the same computer, which is different from IIS 5.1.

4. Windows Process Activation Service (WAS)

The Windows Process Activation Service (WAS) is a new process activation mechanism for Windows Server 2008 that is also available on Windows Vista. It retains the familiar IIS 6.0 process model (application pool and message-based process activation) and hosting features such as rapid failure protection, health monitoring, and recycling, but it removes the dependency on HTTP from the activation architecture. IIS 7.0 uses was to complete message-based activation over HTTP. Other WCF components also insert was to provide message-based activation through other protocols supported by WCF, such as TCP, MSMQ, and named pipes. In this way, applications that use communication protocols can use IIS features such as process recycling, fast failure protection, and a common configuration system that is available only for HTTP-based applications. This hosting option requires the proper configuration of was, but does not require any hosting code to be written as part of the application.

WCF main features of host environment

WCF -8:WCF Service hosting (top)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.