Simulate the basic architecture of WCF using an ASP. NET Program (1)

Source: Internet
Author: User

During the writing of "WCF Technical Analysis", I had a new understanding of WCF. For this reason, I started my third WCF series with the title of the book. The purpose of this series is to supplement the "WCF Technical Analysis" and describe some of the content in the book. It also covers many content that is reluctantly abandoned due to space reasons.

In the first article of this series, I will give a general explanation of the basic architecture of WCF. However, I will find a new way by referring to the familiar ASP. as a request processing platform, NET simulates the architecture of the entire WCF client and server through a simple hosting program. Most of the content in this article is excerpted from Chapter 8 of WCF Technology Analysis volume 1.

Process and components of the WCF framework

Our simulation program builds a mini version of the WCF framework to demonstrate some special components used in the entire process of WCF. First, let's briefly introduce the process for a simple WCF Service call, the process of processing the WCF client and server framework, and the important components used at each stage of the process.

The following list lists the functions provided by the WCF Server framework for processing a simple WCF Service call request and the components carried by the corresponding functions:

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 a 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: deserialization of request messages generates corresponding input parameters for service operation execution, and serialize the return value or ref/out parameter of the service operation execution result, and generate a reply message. Serialization and deserialization are completed through DispatchMessageFormatter

Create a service object: Create or activate a service object instance. IntanceProvider 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 request messages, serialize input parameters to request messages, and deserialize response messages, convert to the return value of the method call or the ref/out parameter. 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 decodes 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.

Sending and receiving of request messages: sending encoded request messages to the server at the transport layer and receiving recovery messages from the server

 
Figure 1 Simplified WCF client and server components

Figure 1 shows the necessary steps for service calling and related WCF components used. In this case, what we need to do is to manually create these components and build a recommended version of the WCF framework using our own code. If you have a clear understanding of the implementation of this case, I believe that the entire WCF framework will not be unfamiliar.

Figure 2 shows the basic structure of the solution in this case, which consists of three projects. Contracts is used to define a service contract and is referenced by the server and client. The client simulates the application through a Console, while the server implements the simulation through an ASP. NET Website.

 
Figure 2 Application structure of the WCF framework simulation case


Related Article

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.