Summary of my WCF journey blog Series

Source: Internet
Author: User
Tags msmq

WCF is a general term for a series of technologies used to build and run interconnected systems. It is a completely new communication platform built on the Web Service architecture. You can regard it as a new generation of Web Service on the. NET platform. WCF provides us with secure and reliable message communication and better interoperability. We can "communicate" with other platforms ".

Microsoft has invested heavily in building WCF for the following two purposes:Integration of existing distributed TechnologiesAndCompliant with the wave of SOA. Before WCF, Microsoft had provided a complete set of distributed-based technologies and products that made it extremely simple to build a distributed interconnected system. Familiar technologies include Enterprise Service,. NET Remoting, XML Web Service, and MSMQ. These different technologies and products provide different implementations for the same functions. For the development of technology, I think "unification" is a main line: In order to enable Web-based development to adopt our Windows Form-based event-driven and control-based development model, we have ASP. to make data with different structures (. NET Object, XML, Relational Data etc) adopts the same operation method, and we have LINQ. Similarly, for the development of a distributed system, it is absolutely necessary to integrate different distributed technologies and provide a unified programming model. WCF is developed for such a purpose.

However, if you think that WCF is simply a combination of these different distributed technologies, it is wrong. When integrating these technologies, WCF always has a guideline, that is, SOA. SOA is undoubtedly a trend of developing interconnected systems in the future. For SOA, I think there is too much information on the Internet. I will not introduce it here. The development of SOA is inseparable from a standard that everyone can respect, and WS-* is the standard. Basically, WCF implements all the current WS-* standards.

After the past six months, I wrote some articles about the introduction to WCF. I named it "My journey to WCF ", the purpose is to share with you how to learn about the WCF journey. Now we will make a phased summary of this series to help readers.
[Article 1st]Create a simple WCF Program
Since Microsoft proposed the. NET strategy, it has successively launched a series of products and technologies, which provide great convenience for us to establish enterprise-level distributed applications on the. NET platform. These technologies and products include. NET Remoting, XML WebSerivce, WSE (2.0, 3.0), Enterprise Service, and MSMQ. By making rational use of the above distributed technologies, we can establish a distributed architecture suitable for different levels of needs. But there are still some problems, that is, the above technologies and products can only solve some problems; for example. NET Remoting. NET platform is a good choice, but considering that it cannot provide interoperability between different platforms. In addition, these technologies are suitable for completely different programming methods, making it difficult for us to move from one to another. For these reasons, we need a new set of technologies to integrate these technologies, so we have today's WCF-Windows Communication Foundation. To build a framework of WCF, we use different technologies to build our distributed applications through consistent programming modes.

Although I have been familiar with WCF for a long time, what I have learned is always fragmented. Now, I want to systematically study WCF and share some of my income with you. I also hope that I can use this opportunity to discuss with you about WCF. If not, I hope you can correct me.

In the beginning, we first set up a simple program to see how WCF works.
[Article 2nd]Endpoint Overview
In fact, WCF builds a framework that enables communication between applications in an interconnected system. So that Developers and effecect do not need to consider how to implement communication problems when building a distributed system, but pay more attention to the business logic of the system. In WCF Infrastructure, the communication between applications is implemented by the Endpoint.
When we Host a WCF Service, we must define one or more endpoints for it, and then the service listens to requests from the Client through this defined Endpoint. When our Application needs to call this Service, because the Client and Service communicate through the Endpoint, we must define the Client Endpoint for our Application. Only when the Client Endpoint and a Service end Endpoint match each other (the Service end can define multiple endpoints for a Service) Can the Client-side requests be monitored by the Service end. That is to say, we can call this Service only when the Client has an Endpoint that exactly matches the Service end. This type of matching is strict. For example, in terms of Address matching, the Endpoint Address of the Client and Service must not only completely match the Service on the URI, but also their Headers must match each other. For Binding, generally, the Client needs a Binding identical to the Service end to communicate with each other.
[Article 3rd]Implement Bi-directional Communication in WCF)

As a comparison of two-way communication in Remoting, we will discuss two-way communication in WCF. In order to better compare the implementation of bidirectional communication in Remoting and WCF, our Sample adopts the same business logic-to call a remote call of a mathematical computation, in addition to passing the corresponding operands, we also pass an object, which can be called back on the Server side to display the operation result on the Client side.

[Article 4th]Serialization in WCF)
In a distributed system, data must be carried when an Application interacts with another Application. System interaction is performed in the form of Message, and the Message is XML. Of course, the data in the Message should also be XML (XML Infoset ). To process these interactive data, we may first think of directly processing XML. At the XML level, we can use the XML technology-XSD, XPath, and XSLT to operate the data. However, to make the XML after processing completely consistent with the requirements, such a job is boring and time-consuming and laborious. What we are best at is using. NET objects to encapsulate our data. How to effectively convert the created object into a structured XML Infoset is what we will talk about today-Serialization.
[Article 5th]Combination of Service-Oriented Architecture (SOA) and Object-Oriented Programming (OOP) -- How to Implement Overloading of Service Contract)
XML-based WCF does not provide native support for Overloading, but Overloading is supported by. NET Framework native. Through Overloading, we can use methods with the same name to define different operations, so that our Code looks more Elegant (Elegant ). If Overloading can be used in WCF, WCF must provide such a Mapping-a method with the same method that is overloaded to map to different Operation. ServiceContract provides a function. Next we will use a Sample to see how to use Overloading in WCF.
[Article 6th]Reasons and solutions for TimeoutException when Duplex Service is called in Winform Application

For a reader who transplanted my demo from the Console Application to the Windows Form, TimeoutException occurs. For more information, see the Messaging of WCF.
[Article 7th]Combination of Service-Oriented Architecture (SOA) and Object-Oriented Programming (OOP) -- How to Implement inheritance of Service Contract

At the programming model level, OO is still an irreplaceable programming mode. So oo is used in Programming, while SO is more used in Architecture. In this case, we must have a cool to reconcile the differences between the two layers that use different principles to achieve seamless integration between them. For example, how to support inheritance, polymorphism, and overload Based on OO behavior. In this regard, WCF provides us with a good solution. Therefore, I said that WCF not only provides technical support for the SOA-based application architecture, but also implements our mission of the "Tuning agent" through relevant mechanisms.

Here we use a Sample to discuss the support of WCF for inheritance. In this Sample, we use a WCF Service to provide weather information, or we implement a WCF Service for weather forecasting.
[Article 8th]Session and Instancing Management in WCF
In a C/S (Client/Service) scenario, Context independence is reflected in that each call to the Service by the Client is completely unrelated. However, in some cases, we want the system to create a Session for us to keep the interaction between a Client and Service. Therefore, like Web Service, WCF also provides support for sessions. For WCF, the interaction between Client and Service is implemented through Soap Message. Each interaction process is a simple Message Exchange. Therefore, from the Messaging perspective, the WCF Session is to include a Message Exchange in the same Conversation. Each Session is uniquely identified by a Session ID.
The real logic is implemented by calling the real Service instance. In a distributed environment, we call the Client to create the final Service Instance. The process is called Activation. In Remoting, we have two Activation Methods: Server Activation (Singleton and SingleCall) and Client Activation. In fact, it has similar Activation for WCF. However, WCF not only creates the corresponding Service Instance, but also constructs the related Context, which we collectively refer to as the Instance Context. Different Activation methods are embodied in the Instance context model in WCF. Different Instance Context modes reflect the correspondence between Proxy, Service call, and Service Instance. In this case, the Instance Context Mode determines the performance of different sessions.
[Article 9th]How to Use tcpTrace for Soap Trace in WCF
Whether for Web Service or WCF, the only form of interaction between Client and Service is to send and receive Soap messages. In our in-depth study of Web Service and WCF, it is necessary to use some Soap Trace tools to thoroughly analyze Soap messages. Among these tools, I think it is best to use the Soap Trace Utility and tcpTrace in Microsoft Soap Toolkit. Let's talk about how to use the tcpTrace tool in WCF today.
[Article 10th]How to perform Exception Handling in WCF
During the development of any Application, it is particularly important to handle unexpected exceptions when performing troubleshooting. For general. NET systems, we can easily implement this function with try/catch. However, for a distributed environment, exception handling is not that simple. According to the Service-oriented principle, we implement reusable business logic in the form of services. Each Service is in an autonomous environment, and one Service needs to interact with another Service, you only need to obtain the Description of the Service (such as WSDL, Schema, and Strategy ). With the help of a standard platform-independent communication architecture, each Service interacts with each other through a standard Soap Message. Service Description, Standard Communication Infrastructure, and Soap Message based Communication enable various services to be loosely coupled. However, since each Service is autonomous, if one Service calls another Service, the Exception thrown by the Service provider must be encapsulated in the Soap Message, in order to be obtained by the user of the service on the other party and then processed reasonably. Next we will use a simple Sample to briefly introduce the methods in which we can perform Exception Handling in WCF.
[Article 11th]Next, let's talk about two-way communication in WCF-Http-based two-way communication V. S. TCP-based two-way communication
In a Service-oriented distributed environment, with a standard platform-independent Communication Infrastructure, each Service interacts with each other through SOAP Message. The interaction process is actually the Message Exchange process. WCF supports different forms of Message Exchange, which is called Message Exchange Pattern (MEP). Common MEP include: Request/Reply, Request/Forget (One-way) and Duplex. By using Duplex MEP, we can perform Callback Client operations on the Service side. Although WCF implements the underlying communication details for us, it transfers our focus to the implementation of business logic for Transport-independent programming, however, understanding the underlying Transport helps us to select a suitable Transport based on the specific environment. Speaking of Transport, WCF often uses the following four: Http, TCP, Named Pipe, and MSMQ. Due to the differences between different protocols, their support for specific MEP is also different. Let's talk about the support for Duplex by Http and TCP today.
[Article 12th]Use MSMQ for Reliable Messaging
In a distributed environment, we often need to transmit data in different ways according to the specific situation. For example, in an Intranet, we generally use TCP for efficient data communication. In an Internet environment, we usually use Http for cross-platform data exchange. These communication methods have a notable feature, that is, they are based on Connection. That is to say, the interaction parties must ensure that there is an available Connection between them during communication. In some cases, for example, users who use dial-up connections and users who use portable computers, we cannot guarantee a reliable connection between them and the Server to be accessed, in this case, the Messaging Queue-based connection is particularly important. Let's talk about how to use MSMQ in WCF today.
[Article 13th]Create MSMQ-based Responsive Service
We know that MSMQ is inherently asynchronous and can only communicate with One-way MEP (Message Exchange Pattern. If One-way MEP is used between the Client and the Service, it means that the Client returns immediately after calling the Service. It cannot obtain the execution result of the Service or capture the Exception of the Service.
However, in some scenarios, this is intolerable. Take Order Delivery in my previous article as an example. The Client submitted an Order to the Service, but could not confirm whether the Order was correctly handled by the Service. This is obviously unacceptable. Today, we will discuss how to create a Responsive Service to solve this problem: the Client no longer knows nothing about the Service execution, it can know whether the Order is correctly handled by the Service.

Author: Artech
Source: http://artech.cnblogs.com
The copyright of this article is shared by the author and the blog Park. You are welcome to repost this article. However, you must retain this statement without the author's consent and provide a clear link to the original article on the article page. Otherwise, you will be held legally liable.

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.