Correlated Local Service Sample

Download sample

This sample demonstrates the use of correlation attributes with local services to raise correlated events to a workflow instance. Correlation attributes must be used on a local service interface when a workflow instance might be listening for different instances of the same event on a local service interface.

In this sample, a workflow creates two tasks and then waits to be notified (by the same local service event) when those tasks are finished. In this case, when external code raises the event to the workflow, the local service infrastructure must rely on data that is in the event that is being raised (the correlation value) to route the event to the appropriate HandleExternalEventActivity activity in the workflow instance.

The ExternalDataExchangeAttribute attribute is a required attribute that indicates that the local service participates in data exchange with a workflow.

The CorrelationParameterAttribute attribute indicates that by default, the correlation value is found on the parameter with the specified name in the methods and events that are defined on the interface. The following code from the sample demonstrates the use of a CorrelationParameterAttribute attribute:

[CorrelationParameter("taskId")]
public interface ITaskService

The CorrelationInitializerAttribute attribute indicates that the attributed method is the one that initializes the correlation value and therefore must appear first in the workflow (before other operations that are defined on the local service interface) for validation to succeed. The following code from the sample demonstrates the use of a CorrelationInitializerAttribute attribute.

[CorrelationInitializer]
void CreateTask( string taskId, string assignee, string text );

The CorrelationAliasAttribute attribute overrides the CorrelationParameterAttribute attribute setting for a specific method or event when the correlation value must be obtained from a location other than the one that is indicated by the CorrelationParameterAttribute attribute.

After each task is created, the task service displays a message box to notify the user that the task was created. When the OK button is clicked, the event to complete the task is raised for the corresponding task ID. These are the same properties that are set on the CreateTask activities, and therefore the events are correlated to the correct TaskCompleted activities.

To build the sample

  1. Download the sample by clicking Download Sample.

    This extracts the sample project to your local hard disk.

  2. Click Start, point to Programs, point to Microsoft Windows SDK, and then click CMD Shell.

  3. Go to the source directory of the sample.

  4. At the command prompt, type MSBUILD <Solution file name>.

To run the sample

  1. In the SDK Command Prompt window, run the .exe file in the CorrelatedLocalService\bin\debug folder (or the CorrelatedLocalService\bin folder for the Visual Basic version of the sample), which is located below the main folder for the sample.

See Also

Reference

HandleExternalEventActivity
ExternalDataExchangeAttribute
CorrelationInitializerAttribute
CorrelationParameterAttribute
CorrelationAliasAttribute

Other Resources

Simple Input Sample
Communications Samples

© 2007 Microsoft Corporation. All rights reserved.