locked
Can CanCreateInstance find existing instances? RRS feed

  • Question

  • Hi,

    Is it possible to have correlation set up so that 'CanCreateInstance' creates a new instance if none exists, but uses the existing instance if one can be found?

    I'm having difficulty setting up such a scenario. I'll provide a link to the full test project source code at the end, so you can tell me where I've gone wrong.

    Let's say I have a simple workflow, with two WCF ReceiveAndSendReply activities. They both receive a simple custom object with a Name property (string) and Value property (int).

    I want all correlations in both ReceiveAndSendReply activities to correlate on the Name property of the parameter.

    The 'First' WCF ReceiveAndSendReply has CanCreateInstance set to true, the 'Second' WCF ReceiveAndSendReply has CanCreateInstance set to false.

    I want calls to 'First' to create the workflow if it doesn't exist. That's fine.

    I want calls to 'Second' to require the instance exist and fail if it doesn't, and succeed (with the proper state) if it does. That's fine too.

    I want calls to 'First' to succeed if the instance already exists - I want it to find the current instance, and use the current instance's state. This doesn't work for me - it gives the error:

    "Operation 'First{http://tempuri.org/}IService' on service instance with identifier '121a2c71-f5eb-4063-8072-9758490f02f4' 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."

    So, is what I want even possible? Or have I failed to grasp some important aspects of correlation and WF4? Also, how is the state managed in a scenario like this, where (if it were possible) you'd then have two 'points of execution' in the same workflow. Any links or documentation on this kind of thing?

    The small test project I created is at:
     http://www.opinionatedgeek.com/Stuff/WFCorrelationTest.zip

    It should compile and run without problems (once you configure the URL - instructions at http://msdn.microsoft.com/en-us/library/ms733768.aspx), and the Workflow1.xaml should be pretty obvious. I just used the WCF test client to send parameter values - keep the parameter 'Name' property the same to see the correlations.

    Many thanks,

        Geoff

    Friday, November 6, 2009 3:22 PM

Answers

  • WorkflowServices enforce the protocol you've defined with your workflow.  Essentially, the workflow you've written is:

    Sequence
        Receive (First, CanCreate = true)
        Receive (Second, CanCreate = false)

    What this means is that while your workflow is waiting for Second it will NOT receive First because the protocol that you've dictated is to sequentially receive a first, followed by a second.

    It sounds like what you want is:

    Sequence
        Receive (First, CanCreate = true)
        Parallel
              Receive (First, CanCreate = false)
              Receive (Second, CanCreate = false)

    You'll notice that the error you're getting shows that it is attempting to pass First to the instance that was created.  It's just that the instance is not currently attempting to receive first ... it is only attempting to receive second.
    Friday, November 6, 2009 6:48 PM

All replies

  • WorkflowServices enforce the protocol you've defined with your workflow.  Essentially, the workflow you've written is:

    Sequence
        Receive (First, CanCreate = true)
        Receive (Second, CanCreate = false)

    What this means is that while your workflow is waiting for Second it will NOT receive First because the protocol that you've dictated is to sequentially receive a first, followed by a second.

    It sounds like what you want is:

    Sequence
        Receive (First, CanCreate = true)
        Parallel
              Receive (First, CanCreate = false)
              Receive (Second, CanCreate = false)

    You'll notice that the error you're getting shows that it is attempting to pass First to the instance that was created.  It's just that the instance is not currently attempting to receive first ... it is only attempting to receive second.
    Friday, November 6, 2009 6:48 PM
  • You're right of course - I think I lost sight of some important workflow concepts there! Sorry for the dumb question.

    Cheers,

        Geoff
    Monday, November 9, 2009 9:44 AM