Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Receive Activities in WF4 fails when persistence is enabled

I have a WF4 workflow with multiple receive functions.

The workflow runs fine until I add persistence. I created the persistence tables and added the following to the \configuration\system.serviceModel\behaviors\serviceBehaviors section of my web.config:

    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true" />
      <sqlWorkflowInstanceStore connectionStringName="InstanceStore"
        instanceCompletionAction="DeleteAll"
        instanceLockedExceptionAction= "NoRetry"
        instanceEncodingOption="None"
        hostLockRenewalPeriod="00:01:00" 
      />
    </behavior>

The workflow accepts a parameter that is an instance of a WorkflowInstanceDTO POCO I have defined.

When I run the workflow with the following code

    var wfi = new WFService.WorkflowInstanceDTO()
    {
        Id = 1,
        InstanceId = new Guid(),
        Description = "Awesome WFI",
        WorkflowId = 1
    };
    proxy.Create(wfi);

It fails on the proxy.Create line with the following error.

An instance key of value '11e5cf14-c2a8-0fbf-d3b5-c12a91c174ff' already exists. This could be because there are multiple MessageQuerySets defined that evaluate to the same CorrelationKey.

When persistence is not enabled, I do not get this error. Has anyone seen this? What am I doing wrong?

like image 911
dgiard Avatar asked Nov 14 '22 05:11

dgiard


1 Answers

Do you initialize correlation and do your receive activities correlate on the same key? You're going to want to read about content-based correlation if you haven't already.

Add a workflow variable called "sharedHandle" of type CorrelationHandle and on your Create call, initialize "sharedHandle" with a "Query correlation initializer". The property would something that all receive calls would accept as an argument.

like image 191
Thelonias Avatar answered Dec 16 '22 04:12

Thelonias