locked
Workflow authorisation with many clients, workflows and users

    Question

  • Hi All,

    I can't seem to find any documentation/examples for situations where a WF application has multiple workflows, not instances but types, defined. 

    I have a scenario where I have multiple clients (companies if you will) using a WF enabled web application. Each of these clients will have 1 or more workflow types available to them. A user of this client will therefore see a list of available workflows that they can start. Before I go to far down the wrong road I wanted to check with you guys as I don't want to duplicate effort and create tables/procedures that are already available for me to record this information in.

    I will have an interface:

    [userid typed in textbox here]
    [workflow to start selected here[ ^ ]
    {start workflow button here}

    I need to populate the second field in that form that is a select box. Looking at the tables provided and the way that WF works (Workflows aren't stored in the database until an instance has been created), I'm looking at creating a ClientWorkflow table that will be the linking table between my Clients and Workflow definitions, in the Workflow table I will hold an ID, the ClassName of the workflow, description (for human consumption). After the user has effectively selected the Workflow ClassName, I can use this to pass to the CreateWorkflow method:

    WorkflowInstance instance = 
                    _workflowRuntime
    .CreateWorkflow(workflowTypeFromDatabase);

    Obviously the select box will only show the Workflows that a linked to the Client whom the employee works for (eg: the ClientWorkflow table).

    • Does this sound reasonable?
    • Am I trying to solve a problem that has already been solved?
    • Will I have trouble starting the workflow from what is affectively a string?

    Any thoughts on this approach appreciated.

    Saturday, October 16, 2010 10:47 AM

Answers

  • Hi,

    That sounds like a reasonable approach. The WF framework doesn't have that sort of functionality built-in, so you would need to do it yourself, and your approach sounds like a good one. You will need to map the string returned from your database onto an actual type that you can pass in to the call to CreateWorkflow, and this type will need to be available to the workflow host for the lifetime of the workflow. One way to do that would be to register the assemblies in the GAC and the use Type.GetType, here are a couple of examples of this:

    http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx

    http://stackoverflow.com/questions/608332/best-way-to-get-a-type-object-from-a-string-in-net

    If your workflows are Xaml workflows and not compiled workflows, then you could use the information from your database to retrieve the xaml and use that for the call to RunWorkflow (but it sounds like you are using compiled workflows since you mention types)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    • Proposed as answer by Andrew_ZhuModerator Wednesday, October 20, 2010 6:53 AM
    • Marked as answer by Tr1stan Wednesday, October 20, 2010 8:50 AM
    Monday, October 18, 2010 2:06 PM
    Moderator

All replies

  • Hi,

    That sounds like a reasonable approach. The WF framework doesn't have that sort of functionality built-in, so you would need to do it yourself, and your approach sounds like a good one. You will need to map the string returned from your database onto an actual type that you can pass in to the call to CreateWorkflow, and this type will need to be available to the workflow host for the lifetime of the workflow. One way to do that would be to register the assemblies in the GAC and the use Type.GetType, here are a couple of examples of this:

    http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx

    http://stackoverflow.com/questions/608332/best-way-to-get-a-type-object-from-a-string-in-net

    If your workflows are Xaml workflows and not compiled workflows, then you could use the information from your database to retrieve the xaml and use that for the call to RunWorkflow (but it sounds like you are using compiled workflows since you mention types)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

    • Proposed as answer by Andrew_ZhuModerator Wednesday, October 20, 2010 6:53 AM
    • Marked as answer by Tr1stan Wednesday, October 20, 2010 8:50 AM
    Monday, October 18, 2010 2:06 PM
    Moderator
  • Thanks Steve, really appreciate you giving me some of your time.
    Wednesday, October 20, 2010 8:52 AM