From theory to practice (6): WCF Architecture

Source: Internet
Author: User
Tags format definition msmq
From theory to practice (6): WCF Architecture

Previous articlesArticleThis section describes the basic knowledge of WCF and the three important components of endpoint: Address, contract, and binding. However, this is nothing more than just a glimpse of the leopard. This article will elaborate on the WCF architecture and repeat the understanding of WCF from the overall perspective.

 

The starting point of this article:

By reading this article, you can learn the following:

    1. Architecture of WCF
    2. Key elements and concepts of the WCF Architecture
    3. Create an exampleProgramAnd parse the architecture

       

Applicable readers:

This article is suitable for beginners of WCF. I can know nothing about it in the past. This article only introduces it and does not involve the specific technical difficulties and introductions of the WCF technology.

 

Architecture of WCF

For the architecture of WCF:

 

Key elements and concepts of the WCF Architecture

Contracts and description (Agreement and description ):

The Protocol defines all aspects of the message system. Including data contract, message contract, and service contract ). Data contract is the format definition for data exchange between the service and client in WCF. It is defined by the XML Schema Definition Language (XSD), so that both the server and client can understand the data format definition. A Message Protocol can define a specific part of a message. By default, a message in WCF is in a fixed format, but in some cases, message contrace can also be used to customize the Message format. The service agreement specifies the method signature exposed by the server. These methods can be called remotely. For example, a is a spy from country C sent to another country. A is responsible for collecting information and being used through a specific channel, send the obtained information to country C. if country A has prepared a set of ciphertext for it before going out to execute the task, only Country C and Special Agent departments and a know the specific meaning of the ciphertext. These ciphertext are the data transmitted between country A and country C, it is exactly the definition of the format of data exchange in WCF, which belongs to the category of Data contract. After receiving the information, a sends the information back to the National Intelligence Agency by telegraph, it first sets the sending Address of the telegram and indicates the source, and encodes the intelligence information into a ciphertext for sending. The format definition of the telegraph message belongs to the scope of message contract, to accept and send task commands to A, the State Intelligence Agency must also provide fixed communication facilities and persons for, the communication facilities and people that can be linked by a belong to the scope of service contract.

Service runtime)

The Protocols mentioned above are formulated during the development of the WCF Service, while some behavior control is performed during the actual operation of the service during the service operation. Errorbehavior is an operation that occurs when a service error occurs. throttingbehavior can limit the number of instances and sessions to be created. Through this, you can control the performance of the WCF Service, metabehavior (metadata behavior) controls whether and how metadata is provided externally. Transactionbehavior can define transactions so that rollback can be performed when an exception occurs. Dispatchbehavior (scheduling behavior) can control the way in which WCF processes messages and customize runtime processes through the scalability. For example, the Message check function is used to check each part of a message. You can use the parameter filter function to perform preset operations based on the filter acting on the message header. Displays the message processing process of WCF.

 

Messaging)

In WCF, messages are transmitted in channels. A channel is a component that processes messages in some way. A group of channels can be combined into a channel stack. There are two main channels: protocol channel and transmission channel. The protocol channel describes the data format and exchange mode. WS-Security is the implementation of the WS-Security Specification that enables security at the message layer. The WS-reliable messaging channel ensures message transmission. The encoder provides a large number of encodings that can be used to meet the needs of messages. HTTP specifies that Hypertext Transfer Protocol should be used to transmit messages. Similarly, the TCP channel specifies the TCP protocol. The transaction flow channel controls the message mode that has been processed by the transaction. You can use the Named Pipe Channel to perform inter-process communication. The MSMQ channel can be used for interoperability with MSMQ applications.

Activation and hosting (activation and bearer)

The final form of the WCF Service is still a program. It can be "self-hosted" or hosted in other applications, such as IIS, Windows activation service, and COM +.

 

Create an example program and parse it according to the architecture Diagram

Create a simple WCF Service and parse it using the above Architecture

Open vs2008 and create a WCF application named wcfsample1, as shown in:

We use the files generated by the system template for parsing. After completing the preceding steps, the following items are automatically generated:

Open iservice. CS,

To briefly describe messagecontract, we create a custommessage. CS,CodeAs follows:

To use this service, we create another servicecontract interface and its specific implementation: imessaginghello. CS and messagehello. SVC, respectively.

And

Configure web. config as follows:

Create a client application project client to consume the services created above. After creating a project, add a service reference, as shown in:

Add the following code to programe. CS after referencing messagehello. SVC and service1.svc respectively:

You can use tcptrace to listen to custom messages.

The message is as follows:

<S: envelope xmlns: S = "http://schemas.xmlsoap.org/soap/envelope/"> <s: body>

The received message is:

<S: envelope xmlns: S = "http://schemas.xmlsoap.org/soap/envelope/"> <s: Header>

It can be seen that messagecontract has played a role.

For how to monitor message messages with tcptrace, see http://www.cnblogs.com/artech/archive/2007/06/14/782845.html

 

References

    1. Http://www.cnblogs.com/artech/archive/2007/06/14/782845.html
    2. Http://msdn2.microsoft.com/en-us/library/ms733128.aspx

       

Example projects in this article

    1. Server and client:/files/jillzhang/wcfsample1.rar
    2. Log File for custom messages:/files/jillzhang/cumtommsg.txt

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.