Using ReceiveAndSendReply Inside a Pick Activity (WF)

Using ReceiveAndSendReply Inside a Pick Activity (WF)

The ReceiveAndSendReply activity template is used in a workflow service to implement a two-way operation. When this activity template is dragged onto the workflow designer, a Sequence activity containing a Receive activity followed by SendReply activity is added to the workflow.

The ReceiveAndSendReply Activity Template in the Visual Studio Toolbox.

The ReceiveAndSendReply Activity Template on the Workflow Designer.

To use the Receive and SendReply activities in a PickBranch, the entire containing Sequence could be placed into the Trigger of a PickBranch, but this is not desirable, since the trigger should contain only the activities that wait for the event that triggers the branch. However, if the Receive or SendReply are dragged out of the Sequence, the following validation error occurs: '__handle1' is not declared. It may be inaccessible due to its protection level. This happens because the Sequence has a CorrelationHandle variable declared, and the Receive and SendReply activities reference this handle to manage the Request-Reply correlation that the runtime uses to ensure that the reply is returned to the correct caller. If either one is moved outside of the Sequence, then the handle variable is no longer in scope and the error occurs.

The SendReply activity is outside of the Sequence that declared the __handle1 variable.

To resolve this, edit the CorrelationInitializers property.

 The CorrelationInitializers property for the Receive activity.

Clicking the ellipsis button brings up the Add Correlation Initializers dialog box.

The Add Correlation Initializers Dialog Box.

You can resolve the issue in one of two ways: you can delete the correlation initializer by clicking __handle1 and pressing delete, or you can replace __handle1 with another CorrelationHandle variable that is scoped higher in the workflow. Deleting the correlation initializer works because workflow services provide some ambient correlation handle management. If multiple Receive/SendReply pairs are not in parallel or overlapping, then the default handle management is sufficient. See Request-Reply Correlation and Correlation Overview for more information about Request-Reply correlation and default correlation handle management.

Once the error is resolved, the Receive activity can be taken out of the Sequence and the Sequence can be removed from the workflow.

Receive and SendReply activities used in the Trigger and Action of a PickBranch.

Now the Receive is in the Trigger and the SendReply is in the Action. For a more extensive sample that uses this pattern, see the Correlated Calculator sample.

Leave a Comment
  • Please add 6 and 1 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Comments
  • Ed Price - MSFT edited Original. Comment: Title casing. Added a tag.

Page 1 of 1 (1 items)
Wikis - Comment List
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Ed Price - MSFT edited Original. Comment: Title casing. Added a tag.

Page 1 of 1 (1 items)