WCF Instance life cycle

Source: Internet
Author: User
Tags hosting
The working principle of WCF

First of all:

WCF's full name is the meaning of the Windows Communication Foundation,windows Communication Foundation, the unified programming model that Microsoft provides for building service-oriented applications, which is integrated. NET platform for all the technologies associated with distributed systems.

Secondly:

WCF is inherently service-oriented. Mainly divided into service side and client two parts. The process of communicating between the server side and the client is shown in the following illustration:

In the figure above, the host process is the server, where the service needs to be created and the service is communicated to the client through endpoint (endpoints). When a client uses a service, it needs to first create a proxy service and then invoke the proxy service.

EndPoint (endpoints) are a very important part of WCF. It contains service addresses (address), binding-frame (Binding), and Contracts (Contract). Where the address defines the location of the service, the binding defines how the service communicates, and the contract defines the functionality provided by the service. To facilitate memory, we refer to the three elements of the endpoint as ABC of the service.

What services are provided by the server, and what are the functions, this is called the contract of the WCF service.

WCF services cannot exist out of thin air. Each WCF service must be hosted (Hosting) in a Windows process that is called the hosting process.

The WCF Service host can be provided by IIS, provided by the Windows service, or by Windows Vista's Windows Activation service. Where IIS hosting is used, only the HTTP protocol is used.

There are three instances of service object creation mode in WCF: Percall, PerSession, single Percall mode workflow is as follows

Client creation proxy object (proxy)
The client invokes a contract operation of the proxy object that the proxy object passes to the service host program
The host application creates a new service contract object and performs the request operation
After the request is executed, if a response is required, the service contract responds to the proxy object and destroys itself

Summary: Percall mode, each time the client makes a request, the server will generate an instance response, after the response has been destroyed. the process for PerSession mode works as follows:

Client creation proxy object (proxy)
The first time the client invokes a contract operation of the proxy object, which passes its call request to the service host
The host program creates a new service object, performs a request operation, and, if necessary, returns a client response
Once the client makes a request to invoke the operation again, the host determines whether there is a established session and, if it exists, does not need to create a new service object, uses the old object directly, or creates a new service object if it does not exist.
The session expires when the specified requirement is reached in time or for some special reason, and the service object is destroyed. Or the client shuts down, and the service object is destroyed automatically.

Summary: persession mode, proxy and service instance corresponding. Different proxy has different service instances. the work flow for single mode is as follows:

Server-side startup while creating service objects
The client invokes the contract operation through the proxy
The service object created in the first step accepts the request, performs the action, and makes the necessary response
The service object created in the first step will remain
Service shutdown, the first step to create the object destroyed

Summary: Only one instance of the server is exchanging messages with the client from beginning to end.

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.