11

We are currently building an application that makes use of a non-simple approval process, which involves multiple levels of approval, returning, reviewing, notifications etc..

Because of the said requirement, we were asked to make use of a workflow framework also to facilitate process transparency.

On the prototype we have succesfully incorporated the workflow and it works fine. however, we cannot determine the actions that should be available to the user. For example, I have the following recieve operations: create(), managerApprove(), RAApprove(), ORMApprove().. now if I call them in order, using the correct user name then they will work. Obviously, if I don't call them in order, then it will throw a FaultException because its not in the correct state. Question is, how will I know which functions are available to expose in the UI - say, if its currently waiting for manager approval then just show an approval button for the manager...

As a workaround, I've created another WCF service that retrieves the same data from the database and then determines the correct UI state (which actions can be performed by the user). I think this is a duplication of logic, since that's supposed in the WF already.

Also, if the WF changes then it my seperate WCF service may potentially break. For example, if I switch the approval order in the workflow then I need to update the logic in the WCF service as well. Otherwise, it would show an invalid page state and clicking approve will invoke the wrong method and cause a FaultException.

Any help will be much appreciated... I'm really new to WF4.

UPDATE:

My colleague put my question this way:

What's the best design for a web app that adopts WF?

The main reasons why WF is being considered - The workflows involved are long running - Workflows are human workflows - they need to coordinate actions of real people - Process Transparency

Also, how should the workflow integrate with the UI? - how will the UI know what state in should be in and what pages to show which users?

Mel
  • 3,058
  • 4
  • 26
  • 40

2 Answers2

5

The workflow itself doesn't expose the information directly. It is there as each pending Receive is a named bookmark and the bookmark name contains the SOAP action it supports as well as the service contract and namespace. The easiest way of getting at this into is by adding the SqlWorkflowInstanceStore to the WorkflowServiceHost and checking the column with the pending bookmarks. It isn't perfect as this will give you the information as it was last persisted which is not necessarily the current state but it has worked for me in a number of applications. Just make sure to set the TimeToPersist to a pretty low value and add some Persist activities in strategic places.

Maurice
  • 27,582
  • 5
  • 49
  • 62
  • I suppose that is a way. but it kind of feels like a hack. – Mel May 26 '11 at 06:12
  • You are right because it is. Whatever gets the job done if there is no good way to do so. – Maurice May 26 '11 at 07:16
  • I was hoping there was a better way... I'm starting to get the impression that WF is actually hurting the design.. feels like we're doing the right thing by using WF but also forced to do "wrong" things as a side effect. – Mel May 26 '11 at 07:54
  • As an alternative hack, would it be better to have the WCF service have the exposed operations, track the transactions itself if you don't want to delve into the workflow's states, and have the WCF service in turn raise the work flow as required? Just feels you'll have better control using the WCF service as the UI's endpoint – Smudge202 May 26 '11 at 08:28
  • Why is it the "wrong" thing? I would have preferred this to be abstracted by the WorkflowControlClient and WorkflowControlEndpoint out of the box. But as it isn't creating a similar abstraction ourself isn't wrong, it is just a bit of extra work we have to do. – Maurice May 26 '11 at 08:30
  • 1
    Ron Jacobs has just added a work item on CodePlex for a new feature like this. Please take a look at http://wf.codeplex.com/workitem/8671 and give us some feedback and votes. – Maurice May 26 '11 at 14:29
  • I'm not really sure what's the in or outs of using WF... that's really the main reason I've asked the question.. "wrong" is just my understanding. Please enlighten me on what should be treated as good and bad practice in terms of WCF and WF.. thanks! – Mel May 27 '11 at 17:40
  • @Maurice thanks for the link, i think that's what I'm looking for. will check it. – Mel May 27 '11 at 17:41
  • What is right and wrong is hard as they are shades of gray and covering all options is impossible in a few posts. I teach a 4 day workflow course and even then I have to leave out a lot of potential interesting material as there are just too much details to go into. – Maurice May 27 '11 at 17:56
0

A very simple approach would be simulating the workflow by managing the status of the approvals. Imagine that you have different buttons/pages for different users to approve different stages ("create", "manager approval", "RA approveal", etc) of the approval process. This is a very old school approach.

If you use this approach, you would need to distribute your workflow (logics/process) accross different places (pages). Obviously, this is a downside of this aproach, specially when your workflow changes a lot or your solutions needs to run different versions of a workflow.

If you want to use Workflow Foundation, the easiest way is what Maurice has suggested.

The other option is to use other tools which would scale more and are more flexible than WF. I have used WF (not the lastest release though), BizTalk, and SharePoint.

If your solution requires interacting with other applications, I would recommned using BizTalk.

gido
  • 31
  • 3