workflow-foundation-4workflow-services

Workflow services and operations not supported by states


I have two workflow services (state machines) that should cooperate and exchange information to accomplish the desired behavior.

The problem I have (but I also had it with only one state machine) is that sometimes I try to send an operation which is not allowed by the current state.

There are two problems: 1) I have to wait the operation timeout to know that the operation was not allowed 2) I'm "masking" real timeouts due to other problems

By now, I found two possible solutions: 1) I can change signatures to return true (allowed) and false (not allowed) and add all operations to all states, (not allowed operations would trigger a self-transition) 2) I always add all transitions to all states (not allowed would trigger a self-transition) but for transitions not allowed I will send an exception

I would like to know which is the best option (and, of course, I'd appreciate other possible solutions too). I would also like to know how I could reply to a request with an exception (maybe throwing it within a try/catch?).

Thanks


Solution

  • Another option here is to use the information in the workflow persistence store. One of the columns contains the active bookmarks and in the case of a Receive activity this is the SOAP operation. You could have a separate service that exposes that information for a given workflow instance.

    You still need to cater of the fact that you might send messages to a workflow that is in a different state because the workflow persistence store isn't updated right away (unless you make it do so) and because multiple people might send messages to the same workflow instance. Still this basic technique works really well and I have used this to enable/disable buttons on the UI based on the state of a workflow.