Correlation Overview

Correlation is the mechanism for relating workflow service messages to each other or to the application instance state, such as a reply to an initial request, or a particular order ID to the persisted state of an order-processing workflow. This topic provides an overview of correlation. The other topics in this section provide additional information for each type of correlation.

Types of Correlation

Correlation can be protocol-based or content-based. Protocol-based correlations use data provided by the message delivery infrastructure to provide the mapping between messages. Messages that are correlated using protocol-based correlation are related to each other using an object in memory, such as a RequestContext, or by a token provided by the transport protocol. Content-based correlations relate messages to each other using application-specified data. Messages that are correlated using content-based correlation are related to each other by some application-defined data in the message, such as a customer number.

Activities that participate in correlation use a CorrelationHandle to tie the messaging activities together. For example, a Send that is used to call a service and a subsequent Receive that is used to receive a callback from the service, share the same CorrelationHandle. This basic pattern is used whether the correlation is content based or protocol based. The correlation handle can be explicitly set on each activity or the activities can be contained in aCorrelationScope activity. Activities contained in a CorrelationScope have their correlation handles managed by the CorrelationScope and do not require the CorrelationHandle to be explicitly set. A CorrelationScope scope provides CorrelationHandle management for a request-reply correlation and one additional correlation type. Workflow services hosted using WorkflowServiceHost have the same default correlation management as the CorrelationScopeactivity. This default correlation management generally means that in many scenarios, messaging activities in a CorrelationScope or a workflow service do not require their CorrelationHandle set unless multiple messaging activities are in parallel or overlap, such as two Receive activities in parallel, or two Sendactivities followed by two Receive activities. More information about default correlation is provided in the topics in this section that cover each specific type of correlation. For more information about messaging activities see Messaging Activities and How to: Create a Workflow Service with Messaging Activities.

Protocol-Based Correlation

Protocol-based correlation uses the transport mechanism to relate messages to each other and the appropriate instance. Some system-provided protocol correlations include request-reply correlation and context-based correlation. A request-reply correlation is used to correlate a single pair of messaging activities to form a two-way operation, such as a Send paired with a ReceiveReply, or a Receive paired with a SendReply. The Visual Studio 2010 Workflow Designer also provides a set of activity templates to quickly implement this pattern. A context-based correlation is based on the context exchange mechanism described in the .NET Context Exchange Protocol Specification. To use context-based correlation, a context-based binding such asBasicHttpContextBindingWSHttpContextBinding or NetTcpContextBinding must be used on the endpoint.

For more information about protocol correlation, see Context Exchange CorrelationDurable Duplex Correlation, and Request-Reply Correlation. For more information about using the Visual Studio 2010 Workflow Designer activity templates, see Messaging Activities. For sample code, see the Durable Duplex and NetContextExchangeCorrelation samples.

Content-Based Correlation

Content-based correlation uses some piece of information in the message to associate it to a particular instance. Unlike protocol-based correlation, content-based correlation requires the application author to explicitly state where this data can be found in each related message. Activities that use content-based correlation specify this message data by using a MessageQuerySet. Content-based correlation is useful when communicating with services that do not use one of the context bindings such as BasicHttpContextBinding. For more information about content-based correlation, see Content Based Correlation. For sample code, see the Content-Based Correlation and Correlated Calculator samples.

你可能感兴趣的:(view)