0
votes

I have a simple workflow created in the workflow designer that has a Receive activity that can be called after the workflow has started. The Receive correlates on one of the content parameters, which is a GUID that I have generated in the workflow and pass back from the initial SendReply activity.

enter image description here

Correlation query: sm:body()/xgSc:DoSomething/xgSc:workflowId

I can execute the workflow with this test method:

[TestMethod]
public void Test()
{
    using (var client = new Test.ServiceClient())
    {
        var workflowId = client.StartWorkflow();
        client.DoSomething(workflowId.Value);
    }
}

This works great, but when I add a SendReply activity to the receive it no longer correlates correctly and I get this error when calling DoSomething:

The execution of an InstancePersistenceCommand was interrupted because the instance key 'aee2a4cc-24ec-9e0e-6f76-31ffe345ae27' was not associated to an instance. This can occur because the instance or key has been cleaned up, or because the key is invalid. The key may be invalid if the message it was generated from was sent at the wrong time or contained incorrect correlation data.

Here's the workflow with the SendReply activity:

enter image description here

Take the SendReply activity back out and it works fine, so somehow the SendReply activity breaks the correlation.

How do I implement correlation with a Receive/SendReply pair?

1

1 Answers

0
votes

For the SendReply activity to function correctly, Request-Reply Correlation must be set up with a CorrelationHandle object.

Firstly, add a new CorrelationHandle type variable to the workflow within the same scope (or higher) as the Receive and SendReply activities.

Variable

Then select the Receive activity and in the properties pane click the CorrelationInitializers button to open the Add Correlation Initializers window.

Click "Add initializer" and type the name of the CorrelationHandle variable.

In the correlation type ComboBox select "Request-reply correlation initializer" and click OK to close the window.

enter image description here

Alternatively, you can put the Recieve and SendReply activities inside a CorrelationScope, which provides an implicit CorrelationHandle to the messaging activities that it contains.

enter image description here