"WCF Technical Anatomy" blog series summary [in continuous UPDATE]

Source: Internet
Author: User
Tags hosting msmq

Http://www.cnblogs.com/artech/archive/2009/11/21/1607686.html

In the last six months, I have been busy with my first WCF monograph, "The Analysis of WCF Technology (Volume 1)" Writing, has been no time to manage their own blog. During the writing of WCF Technical Anatomy (Volume 1), there was a new sense of WCF, starting with the title of my third WCF series. The purpose of this series is to supplement the analysis of WCF technology, to talk about some of the contents of the book, and to include many of the content of the 割弃 for reasons of space.

[1th Article] simulating the WCF infrastructure with an ASP .

In the first chapter of this series, I will give a general explanation of the basic architecture of WCF. However, instead of straightforward the workflow of WCF, I will take a new approach, using the familiar ASP. NET as the request processing platform to emulate the entire WCF client and server architecture through a simple managed program. The source code is downloaded from here.

[2nd] Talk about IIS and ASP.

In September 2007, I wrote three articles detailing the IIS architecture and the ASP. NET runtime pipeline, in-depth descriptions of the monitoring and distribution mechanisms for IIS 5.x and IIS 6.0HTTP requests, and the process of HTTP request processing by the ASP. IIS and ASP. NET runtime pipeline [prev] [Next] "Many people leave a message about why there is no introduction to IIS 7. In the writing of "WCF Technical Analysis (Volume 1)", in order to analyze the IIS-based WCF Service Homestay (Hosting), the relevant content has been studied again, here to share with you.

[3rd] How to perform a non-HTTP-based IIS service Homestay

In introducing IIS7.0, we talked about the http.sys+w3svc implementation of HTTP-based request monitoring, based on the introduction of the following three sets of network listeners (Listener) and Monitoring Adapter (Adapter), the implementation of TCP-based, Named Network monitoring of pipes and MSMQ. tcplistener| TCP Listener Adapter, Namedpipes listener| Named Pipes Listener Adapter, MSMQ listener| MSMQ Listener Adapter. Because IIS 7 provides listener support based on non-HTTP network protocols, it means that we can use non-HTTP communication when we do WCF service boarding (Hosting) over IIS. In this article, we will introduce a non-HTTP IIS service homestay through a simple example, where the source code is downloaded.

[4th] IIS-based WCF Service Homestay (Hosting) Implementation disclosure

With the introduction of the IIS and ASP. NET pipeline, I believe that readers have a general understanding of IIS and the request processing pipeline of ASP. It is relatively easy to understand the implementation mechanism based on IIS service boarding. Broadly speaking, IIS-based service boarding relies on two important objects:System.ServiceModel.Activation.HttpModule and System. ServiceModel.Activation.HttpHandler.

[5th] Creating a WCF service that supports sessions (session) using the ASP. NET Compatibility mode

In the disclosure of WCF Service Homestay (Hosting) implementations based on IIS, we talked about two distinct modes of operation in the adoption of IIS-based (or ASP-based) WCF Service Homestay: ASP. NET Parallel (Side by Side) mode and ASP. NET Compatibility mode. For the former, WCF implements the hosting of the service through HttpModule, while for the latter, WCF's service homestay is implemented by a HttpHandler. Only in the ASP. NET compatibility mode, we are familiar with some of the ASP. NET mechanism can be used by us, such as through the HttpContext request context, based on file or URL authorization, HttpModule extension, identity Simulation (impersonation) and so on.

Because in ASP. NET compatibility mode, ASP. Page handles requests based on. Svc in exactly the same way, in other words, we can maintain session state with the current HttpContext sessionstate to create a WCF Service that supports sessions. Next, we will create such a session service in a simple example by step-by-step.

[6th] Why the baseaddress that are configured under ASP. NET-based application homestay (Hosting) is not valid

This article is from a friend asked me a few days ago to ask questions. The problem is that he says he uses an ASP. Hosting the defined WCF service and sets the baseaddress of the service in the same way, but throws the ServiceHost when creating the InvalidOperationException, and prompted the corresponding address scheme baseaddress found. I realized that this might be related to the logic used in WCF to judge the way a service is hosted, so I asked the friend to migrate the same service boarding code and configuration to the GUI program or console application to see if it was working. As a result, as I thought, everything worked, and personally felt that this should be a bug in WCF. Today, I would like to discuss with you a few ideas on this issue.

[7th] How to implement the integration between WCF and enterlib PIAB, Unity

Prior to that, I wrote an in-depth introduction to the MS Enterlib Piab (see the "Ms Enterprise Library Policy injection Application Block in-depth analysis [summary]"), Also written about the integration of WCF with PIAB (see: WCF Follow-up tour (8): implementation of integration with MS Enterprise Library Policy injection application Block via WCF Extension), Integration of WCF with unity (see WCF Follow-up tour (7): Integration with the Enterprise Library Unity container via WCF extension) and unity with PIAB (see Enterprise Library in-depth analysis and flexible application (1): Through Unity extension implementation and policy injection Application Block integration, "Enterprise Library in-depth analysis and flexible application (7): Again on the integration between PIAB and unity "). Because part of the implementation is based on Enterlib, the previous version of Unity, in the new version (Enterlib V4.1 and Unity 1.2), MS has been redesigned and implemented by unity, so we need to regain this topic, Talk about how to integrate PIAB and unity into WCF for the new Enterlib and unity. (Source code downloaded from here)

[8th Article] The caching mechanism of channelfactory<t> in clientbase<t>

As with traditional distributed remote calls, WCF's service invocation relies on service proxy. The channelfactory<t> is the creator of the service agent. WCF employs endpoint-based (Endpoint) service consumption: WCF services are exposed to potential service consumers through one or more endpoints, interacting with them through the endpoints that match them in the service's consumption. On the client side, we have two typical ways to create service proxies, one is to generate the corresponding service proxy (a type that inherits from clientbase<t>) code and related configuration by importing the service's metadata through tools such as SvcUtil.exe The second is to create a Channelfactory<t> object directly from the corresponding endpoint information (either by code designation or configuration) and directly to the creation of the service proxy using that object.

In fact, even if a service call is made through a Clientbase<t> object, it is internally called the service proxy created by channelfactory<t>. The creation of the entire channelfactory<t> is a relatively complex and time-consuming task that involves many actions such as reflection, configuration file reading, and so on. In order to improve the performance of service calls, in. NET 3.5, WCF introduced the channelfactory<t> caching mechanism in clientbase<t>.

[9th] The service agent can not be closed in a timely manner what will be the consequences?

We want to know something about WCF that the service proxy should close in time as the client makes a service call through a service call. But what happens if the agents of the service are not waiting to be closed in time? What to turn off the service agent? Do I need to turn off the service agent at all times? Are there some exceptions? This article will focus on these issues.

[10th] How the client calling the WCF service should handle exception handling

In the previous article (the service agent can not be closed in a timely manner what are the consequences?), we talked about the importance of closing the service proxy in a high concurrency environment in a timely manner, and clarified its root cause. But is it all right to call Icommunicationobject's Close method to shut down the service proxy? It's far from easy, and there are some things to be done about exception handling, which is the topic of this article.

[11th] Application of asynchronous operations in WCF [prev] [Next]

We can divide the operations into CPU-bound (CPU Bound) operations and I/O-bound (I/O Bound) operations by performing the required resource types. For the former, the operation is mainly CPU-intensive calculation, and for the latter, most of the operation processing time is spent in I/O operations processing, such as access to the database, file system, network resources. For I/O binding operations, we can take advantage of multi-threaded mechanisms that allow multiple operations to execute concurrently on their own threads, improving system performance and responsiveness. Service invocation is a typical I/O binding operation, so multithreading has a wide range of applications in service invocation. In this article, we specialize in the application of multithreading or asynchronous operations in WCF.

[12th] Data Contract (contract) and Data Contract serializer (DataContractSerializer)

Most of the systems are data-centric, and the implementation of the functions is based on the correct processing of the relevant data. And the data itself, is the carrier of effective information, in different environments have different representations. A distributed interconnected system focuses on the exchange of data, and the fundamental premise of the normal exchange of data is the consistent understanding of data structure between the parties involved in the exchange. This is for the performance of the data requirements, in order to ensure that different platforms, different manufacturers of applications can be normal data exchange, the exchange of data must be in a way that everyone can understand the presentation. In this respect, XML is undoubtedly the best choice. So serialization under WCF (serialization) solves how data is transformed from the object's representation into an XML representation to ensure the normal exchange of data.

[13th] Known types in the serialization process (known type)

DataContractSerializer carries the serialization and deserialization of all data contract objects. In one of the previous articles (data contract and Data Contract serializer (DataContractSerializer)), we talked about DataContractSerializer basic serialization rules , how to control the number of DataContractSerializer serialization or deserialization objects, and how to save the object reference structure of the serialized object in the serialized XML. In this article, we will discuss in detail one of the important topics in WCF serialization: Known types (known type).

Serialization and deserialization under WCF addresses the transformation of data between two states: Managed Type objects and XML. Because a type defines the data structure of an object, you must determine the type of the object beforehand, whether for serialization or deserialization. Serialization or deserialization will fail if the object being serialized or the resulting deserialization contains an unknown type. To ensure the normal serialization and deserialization of DataContractSerializer, we need to add the "unknown" type to the DataContractSerializer "known" Type list.

[14th] Generic Data contract and collection data contract [Prev] [Next]

In the. NET Framework 2.0, generics are introduced for the first time. We can define generic interfaces, generic types, generic delegates, and generic methods. Serialization relies on real and specific types, whereas generics deliberately blur the concept of specific types. Instead, a collection represents a group of objects, and the collection has an iterative (Enumerable) feature that iterates through each element of the collection through an iterative rule. I'll cover this in more detail in this article because the paradigm types and collection types have some special behaviors and rules on serialization and deserialization.

[15th] The role of the Data Contract agent (Datacontractsurrogate) in serialization

If a type is not necessarily a data contract, and a given data contract is very different, we want to serialize the object of that type to XML based on the data contract. Conversely, for a given data-contract-based XML, how do we implement such a scenario by deserializing the object of that type?

[16th] equivalence of data contracts and versioning

A data contract is a description of the data structure used for the interchange, and is the basis for serialization and deserialization. In a WCF application, the client and the server must pass an equivalent data contract to enable efficient data exchange. Over time, inevitably, we are faced with changes in the version of the data contract, such as the addition and deletion of data members, member names or namespace corrections, how to avoid the data contract version of the changes to the client's existing programs, this is the topic of important discussion.

[17th] News (message) detailed [prev] [medium] [next]

Message exchange is the only means by which WCF communicates, and service access, which is represented by method call, needs to be translated into specific messages and encoded (Encoding) to be sent to the server via a transport channel The result of the service operation execution can only be returned to the client in the form of a message. Therefore, the message is at the core of the entire WCF architecture, and WCF can be seen as a conduit for message processing.

Although the message is so important in the entire WCF architecture, the general WCF programmer is unaware of the presence of the message. The reason for this is simple, the goal of the WCF design is to implement all the details of message communication, providing a fully object-oriented programming model for the final programmer. So for the general programmer, they are facing the interface, but do not know the service contract for the service description, the face is the data type, but do not know the role of the data contract for serialization, the face is the method call and return value of the acquisition, but do not understand the underlying message exchange process.

We encourage you to learn more about WCF's process for message processing with two purposes: first, high-quality WCF programs can be written only on the basis of a clear understanding of the entire message processing process. Second, WCF is a highly scalable communication framework that gives you the flexibility to create custom WCF extensions (WCF Extension) to implement the functionality you need. Like the plug-ins of WCF, these custom WCF extensions participate in a plug-and-play approach to the entire WCF message processing process. Understanding the WCF entire message processing process is a prerequisite for a flexible WCF extension.

[18th] Message contracts (messages contract) and serialization based on message contracts

In this article, we will discuss the message contract for one of the four major WCF contracts (service contracts, data contracts, message contracts, and error contracts) (MSG contract). The service contract focuses on the description of the service operation, and the data contract focuses on the description of the data structure and format, while the message contract focuses on the matching relationship between the type member and the message element.

We know that only serializable objects can be passed between the client and the server through a service invocation. So far, We know that there are two types of serializable types: one is the System.SerializableAttribute attribute is applied or the type of the System.Runtime.Serialization.ISerializable interface is implemented, and the other is the data contract object. For service operations that are based on these two types, The client formats the input parameter into a request message via System.ServiceModel.Dispatcher.IClientMessageFormatter, and the input parameter is placed in the body of the message as a payload, and the execution result of the service operation is System.serv The IceModel.Dispatcher.IDispatchMessageFormatter is serialized as the body of the reply message.

In some cases, there is a requirement that when serializing an object and generating a message, you want to use part of the data member as the header of the soap and partly as the body of the message. For example, we have a service operation that uses a stream to upload a file, in addition to streaming the contents of a binary representation of the file, but also to transfer an additional file-based attribute information, such as file format, file size and so on. The general practice is to transfer the stream of file content as the body of soap, passing its property contents as the soap's header. Such a feature can be implemented by defining a message contract.

[19th] Depth Profiling message encoding (Encoding) implementation [Prev] [Next]

The message is the only medium in which WCF communicates, and it ultimately needs to be passed through to the transport layer. A precondition for the transmission of the message or an essential task is to encode the message accordingly. WCF provides a range of alternative encodings, each with advantages in interoperability and performance. In this article we will discuss the various coding methods for the message.

From the point of view of interoperability, the coding approach largely determines the ability to support cross-platform. Some encodings are platform-independent and some are limited to a specific platform. WCF provides 3 typical encoding methods: Binary, Text, and Mtom. The binrary encodes the message in binary mode, but only. NET platform, and text provides platform-independent, literal-based encoding. MTOM encoding is based on the Ws-mtom specification, which is of great significance for improving the transmission performance of large-scale binary data in the SOAP message, since the coding method follows the corresponding specification, which is undoubtedly a cross-platform encoding method.

[20th] How is the service described in the WCF system?

Any program needs to run in a deterministic process, which is a container that contains the resources required for the program instance to run. Similarly, the monitoring and execution of a WCF service also needs to be hosted by a process. The way we will create or specify a process for a WCF service is called Service Hosting. The nature of service boarding in some way, create or specify a process to listen for service requests and perform service operations, providing a running environment for the service.

There are two ways to host a service: one is to create a hosted application for a set of WCF services, to host the service by manually starting the program, and all managed applications can host the WCF service, such as the console app, Windows The Forms application and the ASP. NET application, we refer to this way the service boarding way is called self Hosting. Another is the hosting of WCF services through the existing process activation of the operating system, including IIS, Windows Service, or was (Windows Process Activation Service) under Windows.

The service homestay is to create a ServiceHost object (or any object that inherits from ServiceHostBase) for a WCF service type. Regardless of the boarding method, during the process of creating a ServiceHost for a service, a series of actions are performed internally within the WCF framework, the most important of which is to create a service descriptionfor the service Description. In this article, we'll cover the service description in a comprehensive way.

[21st Article] WCF basic exception handling mode [prev] [medium] [next]

Because WCF uses. NET Managed languages (C # and net) as its primary programming language, it is not possible to be complicated by the way WCF-based programming is destined. At the same time, one of the purposes of WCF design is to provide communication implementations based on non-business logic, providing programmers with an easy-to-use Application programming interface (API). The simplicity of the WCF programming pattern is also reflected in exception handling, and the main purpose of this article is to make a simple introduction to the WCF-based exception-handling programming model.

[22nd] Deep analysis of WCF underlying exception handling framework implementation principles [Prev] [medium] [next]

For the previous article (WCF basic exception handling mode: [prev], [medium], [next]), mainly on the perspective of the final developer on the WCF about exception handling programming patterns, we need to move our eyes to the inside of the WCF framework, in-depth analysis of the entire WCF exception processing process.

[23rd] How the service Instance lifecycle controls [prev] [medium] [next]

The purpose of service invocation is to consume the function of a service, and the realization of the function is defined in the corresponding service type. Regardless of how complex the WCF service-side framework processes the process of service invocation requests, it is ultimately implemented on the activation and operation methods of the service instance. Instance management in WCF (Instance Management) is designed to address the activation of service instances and the control of Service instance lifecycles.

The purpose of the session is to maintain the state between multiple service invocations from the same client (service proxy). From the point of view of message exchange, a session uses a message recognition mechanism to determine the source of a call to a service, thereby associating all messages from the same client. Therefore, the session implements the Message Association (MSG Correlation).

An instance session is a very important two feature of WCF, which is both relatively independent and mutually restrictive. The different combinations of instance patterns and the degree of support for the session will make the final service behave differently. The rational use of instance management and sessions plays a decisive role in improving and improving the scalability (Scalability), Performance (performance), throughput (throughput) of WCF service applications.

[24th Article] How does the Servicedebugbehavior service behavior implement exception propagation?

Only the faultexception exception thrown by the server can be serialized into a fault message and propagated to the client. For generic exceptions (such as the dividebyzeroexception that are thrown by the divide operation), the exception information cannot be delivered to the client by default. However, if Servicedebugbehavior is applied to a service and the includeexceptiondetailinfaults switch is turned on, the exception information is propagated to the client intact. How does WCF internally handle thrown non-faultexception exceptions?

[25th] meta-data (Metadata) architecture system panorama [WS Standard Article] [Data description]

In WCF profiling (Volume 1), I have repeatedly emphasized to the reader the nature of WCF's communication: Endpoints are the means by which clients communicate with the server. The provider of the service publishes the service through one or more endpoints, and the service's consumers make calls to the service by creating a matching endpoint. At the point of view of the service consumer, how do you create such a "match" endpoint? Or, what information does the client create that can effectively invoke the target service's endpoint? This is the problem that metadata needs to solve.

[26th] How to export metadata for WCF services (METADATA) [implementation] [extensions]

The export of metadata is the process of implementing the transformation from ServiceEndpoint object to Metadataset object, and the export of metadata is implemented by Metadataexporter in the WCF metadata framework system. Metadataexporter is an abstract type that defines the basic behavior of exporting meta data. WCF defines a specific metadataexporter:wsdlexporter that generates a WSDL-based metadataset based on an endpoint's metadata export. Let's get to know Metadataexporter and Metadataset first.

The binding element of the WSDL is derived from the bound object of the endpoint, so how are these binding-based metadata and the corresponding policy assertions written to the WSDL? The WSDL Export extension (WSDL exported Extension) and the policy export Extension are designed for this purpose.

[27th] How to publish a service into wsdl[programming [based on Ws-mex] [implementation based on Http-get]

For the WCF service-side metadata architecture, the end point of the service is exported to Metadataset through Metadataexporter, only half of the work is done. The metadata that has been successfully exported as a Metadataset object needs to eventually be published as a network resource that can be accessed, to be obtained by the service consumer, and thus effectively to help them make service calls. The release of metadata is ultimately achieved through a service behavior such as ServiceMetadataBehavior.

A service form such as ServiceMetadataBehavior can be applied to the corresponding service programmatically or by configuration to implement a metadata publishing mechanism based on http-get or Ws-mex . So what is the specific implementation principle within WCF? I believe a lot of people are curious about this, this article is for you to reveal its essence.

[28th] Get the metadata by yourself [source code DOWNLOAD]

The way metadata is published determines the behavior of metadata acquisition, and the WCF Service metadata architecture system realizes metadata distribution based on Ws-mex and http-get through ServiceMetadataBehavior, and the implementation of metadata is different for these two kinds of protocols. , this piece of the article through its own way of metadata acquisition, can be seen as a WCF client metadata framework simulation.

[29th] Call WCF services in different ways [provide source code download]

We have two typical WCF invocation methods: Import the published service metadata by SvcUtil.exe (or add a Web reference) to generate the code and configuration for the service agent, and create the service proxy object through ChannelFactory. In this article, we take a unique approach to service invocation.

[30th] A useful WCF calling programming technique [prev] [Next]

In a WCF service call based on a session channel, we need to close the channel in a timely manner due to the number of concurrent channels, and we need to forcibly abort the (abort) channel when we encounter some exceptions. In real enterprise development, just as we don't normally let developers manually control the opening and closing of database connections, we generally don't let developers manually create, open, abort, and close channels, which is what the framework should do. In this article, let's go through some programming techniques that allow developers to ignore the existence of a "channel", making service calls like calling a normal object.

"WCF Technical Anatomy" blog series summary [in continuous UPDATE]

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.