locked
Invoke another workflow from current workflow RRS feed

  • Question

  • Hi,

    I'm using WF 4 and in my project I have created two workflows wich depend on eachother.

    The first workflow needs to start an instance of the second workflow. Then when the second workflow is finnished it needs to tell the first workflow about it.

    Questions:

    1. How can I start the second workflow from my first?

    2. How can the second workflow notify the first that it's done?
    Friday, February 5, 2010 12:50 PM

Answers

  • I figured it out.
    It's two WorkflowService in the same project. So I just added them both as Service Reference. Then after rebuilding the solution the activities nicely appear in the toolbox  :)

    • Marked as answer by mimolo Friday, February 26, 2010 2:11 PM
    Friday, February 26, 2010 2:11 PM

All replies

  • If this is an activity library or a console app and your workflows are Workflow1.xaml, and Workflow2.xaml, the easiest way to do this should be to
    build your project, open Workflow1.xaml, and drag in a 'Workflow2' from the toolbox.

    (There have been some bugs where Workflow2 doesn't automatically show up in the toolbox, even though the project builds successfully, if this applies to you, I'll try to find you the related info.)

    Tim
    Friday, February 5, 2010 8:31 PM
  • Thanks for your reply Tim

    It's not a console app. It's a workflow app with two workflows like you describe...

    Workflow 2 does not appear in the toolbox  :(  so I can't drag it in...
    Friday, February 5, 2010 8:47 PM
  • OK, the info I could find is that this not showing up is a known issue for Beta 2

    forum thread (Custom CodeActivity not showing up in Toolbox)

    toolbox issue with custom activities (mostly in the comments)

    What you could do for a workaround is add it in XAML. For a workflow named MyNamespace.MyWorkflowName in the SAME assembly like this scenario, it would look like this:

    in the root <Activity> tag add the xmlns of the activity    xmlns:localmyns="clr-namespace:MyNamespace"

    Then where you want your activity, it will be encoded as

    <localmyns:MyWorkflowName />

    Once you edit the XAML to a valid state, you should be able to load it up in the workflow designer and view it again.

    Tim

    (PS: Slightly different format applies for using a workflow in a DIFFERENT assembly, and for Workflow Service Xamlx files, see post below)

    • Proposed as answer by Amadeo Casas - MSFT Friday, February 5, 2010 9:29 PM
    • Unproposed as answer by mimolo Saturday, February 6, 2010 12:26 AM
    • Edited by Tim Lovell-Smith Saturday, February 6, 2010 1:37 AM PS
    Friday, February 5, 2010 9:10 PM
  • ok here's what I've tried, and don't get to work:

    created an workflow activity - TestActivity1.xaml

    1. in the root of the activity I put in  xmlns:localmyns="clr-namespace:MyWorkflowServices"

    2. I added this tag <localmyns:Workflow2 />

    3. Compiler error:
    Could not resolve type '{clr-namespace:MyWorkflowServices;assembly=_XamlTemporaryAssembly_, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null}Workflow2'.


    Workflow1 and Workflow2 are both in my Project: MyWorkflowServices
    Saturday, February 6, 2010 12:25 AM
  • Oh, this is a workflow services project? I wasn't clear. In that case there are different rules!
    Please try including the assembly name in the XMLNS:

    xmlns:localmyns="clr-namespace:MyWorkflowServices;assembly=MyWorkflowServices"

    Tim
    Saturday, February 6, 2010 1:11 AM
  • Nope, doesn't work...

    System.Xaml.XamlObjectWriterException: Cannot create unknown type '{clr-namespace:TestWorkflows;assembly=TestaWorkflows}Service2'.

    In the root element <WorkflowService of my Service1.xamlx I put line 1, then I've put one testactivity (Activity1) and after that I tried to put in Service2

    1. xmlns:localmyns

     

     

    ="clr-namespace:TestWorkflows;assembly=TestWorkflows"
    |
    |
    |
    <
    t:Activity1 sap:VirtualizedContainerService.HintSize="255,22" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />

     

    <

     

    <

     

    <

    <

     

     

    localmyns:Service2 />

    Saturday, February 6, 2010 9:08 AM
  • Hm, maybe it's that I still didn't understand the scenario.

    Am I now understanding that you want to invoke one workflow Service (Service2) from another Service (Service1.xamlx)?

    [i.e. We're not doing the invoke Activity1 from the Service?]

    If so, I've been on totally the wrong track.

    Tim
    Saturday, February 6, 2010 10:19 AM
  • Sorry, if it's been hard to understand...  :)

    This is the scenario:

    1. I have two workflows

    2. WorkflowService1 starts

    3. WorkflowService1 gets a value, and must start an instance of WorkflowService2(sending a variable)

    4. WorkflowService2 starts and uses the variable WorkflowService1 sent to complete its flow

    5. WorkflowService2 tells Workflow1 that it's finnished

    6. WorkflowService1 can finnish
    • Edited by mimolo Sunday, February 7, 2010 9:46 AM
    Saturday, February 6, 2010 10:34 AM
  • And they're both services? Or not? :-)
    Running on the same host or different?
    Tim

    Sunday, February 7, 2010 1:46 AM
  • yepp, both services and on the same host

    Sunday, February 7, 2010 8:55 AM
  • Why do you use two workflow services? That makes no sense for me. Note that a WorkflowService is NO Activity! I would use a composite-activity instead of service 2.
    Monday, February 8, 2010 10:10 AM
  • But, if from wf services1 must make multiple call to wf services 2 and every instace of wf services 2 when are finished must signal somehow to services 1 ? It's this scenario possible?
    Tuesday, February 23, 2010 8:59 AM
  • @pcc
    Yes it is possible - but you need to use add service reference (from the project context menu), or Send/Receive reply activities. You can't just drag+drop from toolbox.

    Tim
    Tuesday, February 23, 2010 11:52 PM
  • I figured it out.
    It's two WorkflowService in the same project. So I just added them both as Service Reference. Then after rebuilding the solution the activities nicely appear in the toolbox  :)

    • Marked as answer by mimolo Friday, February 26, 2010 2:11 PM
    Friday, February 26, 2010 2:11 PM
  • Hi mimolo,

    I need to do the same thing... could you please elaborate on how you managed to invoke a workflow from another.

    Please help on this account. I ve a deadline coming up

    Shiva

    Thursday, April 22, 2010 5:25 AM
  • As I described in my answer I had two workflowServices in my workflowService proj.

    I added them both as Service References into the solution. Build the solution. Then you will see them in your toolbox, and you can drag an activity from workflowservice1 into workflowservice2.

    Hope that helps!

    Thursday, April 22, 2010 6:56 PM