With correlation, CanCreateInstance means AlwaysCreateInstance?


  • Maybe I'm misunderstanding how correlation is supposed to work. To keep it simple, I have a workflow with two operations:

    OperationA(int id, int value) [CanCreateInstance = true]

    OperationB(int id)

    OperationA kicks off a new workflow, and OperationB completes the workflow. I'm correlating the id passed in with the workflow identity/instance.

    Scenario 1 (Happy):

    Service client calls OperationA(x, y) => a new instance appears in my persistence store. Happy.

    Another service client then calls OperationB(x) => the instance is removed from the store. Happy.

    Scenario 2 (Happy):

    Service client calls OperationB(x) => error "The execution of an InstancePersistenceCommand was interrupted because the instance key 'blah' was not associated to an instance". Catchy.

    Scenario 3 (Sad):

    Service client calls OperationA(x, y) => a new instance appears in the store. Happy.

    Another service client calls OperationA(x, y) => another instance appears in the store, and error "An error processing the current work item has caused the workflow to abort"

    Yet another service client calls OperationB(x) => the first instance is removed from the store. Happy.

    At the end of this scenario I'm stuck with a broken aborted instance in the store, which to my thinking should never have existed, since the second call to OperationA should have realized there was already an instance correlated to the given id, but since the operation invoked is out-of-order with respect to that instance, an exception is obviously still warranted.

    It appears that the CanCreateInstance flag is causing that operation to always create an instance.

    What am I missing?

    • Edited by wbradney Tuesday, May 21, 2013 6:04 PM
    Tuesday, May 21, 2013 5:59 PM

All replies

  • OK, and now as a result of tinkering with my CorrelationInitializers I've broken something and now I can't even get scenario 1 and 2 working again. Now for OperationB I always get:

    There is no context attached to the incoming message for the service and the current operation is not marked with "CanCreateInstance = true". In order to communicate with this service check whether the incoming binding supports the context protocol and has a valid context initialized.

    Clearly I don't understand correlation. This message refers to "context protocol", and yet I thought I was specifying Content-based correlation ("Query correlation initializer"). Very confused.

    • Edited by wbradney Tuesday, May 21, 2013 7:57 PM
    Tuesday, May 21, 2013 7:55 PM
  • I think I may have figured out how to make this work, but I still don't feel like I understand the various correlation settings.

    What I did was delete the CorrelationHandles from all Receive activities, clear the CorrelatesWith property on all Receive activities, clear all entries in CorrelationInitializers on all Receive activities, and then make sure that ONLY a single entry exists in CorrelatesOn, appropriate for mapping to that message's parameter.

    Now the workflow works as expected, and I even get a much more appropriate error for Scenario 3:

    Operation 'blah' on service instance with identifier 'blah' cannot be performed at this time. Please ensure that the operations are performed in the correct order and that the binding in use provides ordered delivery guarantees.

    If anyone can give me some pointers to better understand these settings I'd appreciate it.

    UPDATE: This worked for my test project, which contains a simple sequential workflow. When I applied a similar correlation scheme to my real project (which uses a state machine), Scenario 3 gives me a TimeoutException on the second call to OperationA. Sigh.

    UPDATE: I get the same TimeoutException if I change the StateMachine to a simpler Pick activity. What's going on here? Why does this only work when configured as a simple sequence of two Receive/SendReply activities?

    • Edited by wbradney Wednesday, May 22, 2013 3:55 PM
    Tuesday, May 21, 2013 11:57 PM
  • For what it is worth, I seem to be experiencing the same problem with the state machine workflow.  I would so love to see the "cannot be performed at this time" error!  
    Saturday, May 25, 2013 2:08 AM