Introduction to WCF

Source: Internet
Author: User

By studying Jiang Jinnan's blog post, I have gained a new understanding of WCF. However, I still cannot say that I have a general understanding of WCF, but I still have a vague understanding of some concepts. Here, I will summarize some of the things I learned recently. Part of the content is taken from the blog series of Jiang Jinnan.

First, we will introduce the communication process of WCF:

WCF Server framework:

 Request Message receipt and reply message sending:The server listens to and receives requests from customers at the transport layer, and sends the encoded reply message to the client through the transport layer.

 Request Message decoding and response message encoding:The received byte array is decoded to generate the request message object, and the reply message is programmed into a byte group. Message encoding and decoding are completed through messageencoder, while messageencoderfactory creates this object.

Deserialization of request messages and serialization of response messages:Deserializes request messages, generates input parameters for service operation execution, serializes the result of service operation execution (return value or ref/out parameter), and generates response messages. Serialization and deserialization are completed through dispatchmessageformatter

Create a service object:Creates or activates a service object instance. instanceprovider is used to create or obtain a service object.

Service Operation execution: Call the operation method of the created service object and pass in the input parameters generated by deserialization. Operationinvoker completes the final execution of service operations

Compared with the server process, the client process is relatively simple and only contains the following three necessary stages:

Serialization of request messages and deserialization of response messages:Generate a request message, serialize the input parameters to the request message, and deserialize the Response Message to convert the returned value or ref/out parameter of the method call. Serialization and deserialization are completed through clienthmessageformatter

Encoding of the request message and decoding of the reply message:Encode the request message to generate a byte array for sending by the transport layer, and decode the byte array received by the transport layer to generate a recovery message. Message encoding and decoding are completed through messageencoder, while messageencoderfactory creates this object.

Send request message and receive reply message: Sends encoded request messages to the server at the transport layer, and receives recovery messages from the server.

In the entire communication process, the client and server compile and parse messages based on data contracts, service contracts, and message contracts, just as they comply with network protocols during network transmission, the contract here is a simple standard developed by developers themselves.

I have always been confused about the concept of service orientation, and I am not very familiar with it yet. WCF is service-oriented. WCF supports multiple protocols and can host on was and ASP. NET (parallel mode or compatible mode ).

First, describe the structure of iis7.0 and ASP. NET:

Was is responsible for configuring listening requests and managing processes. Whether it is an HTTP request received from W3SVC or a request received through a listener adapter provided by WCF, will be passed to was. If the corresponding Worker Process (or application pool) has not been created, it is created; otherwise, the request is distributed to the corresponding Worker Process for subsequent processing. During request processing, was loads the relevant configuration information through the built-in configuration management module to configure the relevant components.
In 5.x and IIS 6.0, the storage of metabase-based configuration information is different from that in IIS
7.0 most configuration information is stored in xml configuration files. The basic configuration is stored in applicationhost. cofig.

Iis7.0 is also integrated with ASP. NET. For example, it brings us the following benefits:

Allows us to use native code and managed code
The IIS module is registered in IIS to form a common request processing pipeline. By these IIS
The queue composed of modules can process all requests, regardless of the resource type of the request. For example, you can apply the forms authentication provided by formsauthenticationmodule to requests based on. aspx, CGI, and static files.
Apply some powerful functions provided by ASP. NET to areas that are hard to match. For example, place the URL rewriting function of ASP. NET before authentication;
Implement, configure, detect, and support some server features in the same way, such as module, Handler ing, and custom error configuration (custom
Error configuration.

What does a complete network response process look like?

In w3wp.exe, use aspnet_ispai.dll to load. Net Runtime (if. NET is not loaded at the time of running ). A worker process corresponds to an application pool. An application pool can host one or more web applications, and each web application maps to an IIS virtual directory. Each web application runs in its own application domain.

If HTTP. the HTTP request received by sys is the first access to the web application. When the runtime is successfully loaded, it creates an application domain (appdomain) for the Web application through appdomainfactory ). Then, a special runtime isapiruntime is loaded. Isapiruntime is defined in the assembly system. Web, and the corresponding namespace is system. Web. hosting. Isapiruntime takes over the HTTP request.

Isapiruntime will first create an isapiworkerrequest object to encapsulate the current HTTP request and pass the isapiworkerrequest object to ASP. net runtime: httpruntime. From now on, the HTTP request has officially entered ASP.. Net pipeline. According to the isapiworkerrequest object, httpruntime will create a context object used to represent the current HTTP Request: httpcontext.

With the successful creation of httpcontext, httpruntime will use httpapplicationfactory to create a new or obtain an existing httpapplication object. In fact, ASP. NET maintains an httpapplication Object pool. httpapplicationfactory selects available httpapplication users from the pool to process HTTP requests. After processing, it is released to the object pool. Httpapplicationfactory is responsible for processing the current HTTP request.

During the httpapplication initialization process, the corresponding httpmodule object is loaded and initialized according to the configuration file. For httpapplication, different events are triggered at different stages of HTTP request processing. The significance of httpmodule is to register the corresponding events of httpapplication, inject the required operations into the processing process of the entire HTTP request. Many functions of ASP. NET, such as identity authentication, authorization, and caching, are implemented through the corresponding httpmodule.

The final implementation of HTTP request processing is another important object: httphandler. Different resource types have different httphandler types. For example, the httphandler corresponding to the. ASPX page is system. Web. UI. Page, and the httphandler corresponding to the. SVC file of WCF is system. servicemodel. Activation. httphandler.

For ASP, WCF inserts data in the httpmodule stage to implement final response to the client logic.

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.