I’m getting to grips with WF4, and am currently experimenting with a proof of concept design for a simple Expenses Approval system. I want to use WorkflowService hosted in IIS to enable a web client to submit approvals. My current design is as follows (assume we’re just passing in an expenseID and a isApproved boolean to the Receive activities):
WF4 Expense Workflow http://i56.tinypic.com/esohno.jpg
One aspect I’m unclear about is that, the client would need to know exactly which Receive activity to call next. To do that the client would need to know exactly where the workflow is at (by querying a datasource), switching on some sort of state flag, and calling the appropriate Receive activity. But in doing this surely I’d be bypassing the point of using a persisted workflow?
It could just be that my design is plain wrong, so I’d welcome any input or guidance on how best to acheive this task or improve the design.
You can achieve this result, but you should provide API documentation with your service contract to attempt to make this behaviour clear to your clients. The WSDL of the service will not make this clear by itself.
With regard to the implementation, the only way to achieve this is outside WF. This is because you will get a content correlation error on loading the workflow when the client attempts to invoke a service method that it is not allowed to call according to the workflow flowchart rules.
The WF service host will not be able to load the persisted workflow instance and will therefore throw an error that you will need to catch in a WCF IErrorHandler. You will then need to determine what the scenario is and convert the exception into a service fault that can be understood by the client.
I wrote a blog post a while ago the provides an example of how this works – http://www.neovolve.com/post/2010/11/09/Managing-content-correlation-failures.aspx.