Windows Workflow Foundation (WF4) - How To Invoke a Child Workflow as XAML

Demonstrates how a workflow can invoke another workflow that is loaded as XAML from a file or a database. 

C# (5.1 MB)
3.8 Star
3,620 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Is this activity included in WF 4.5
    1 Posts | Last post September 06, 2014
    • Is something like this included in WF 4.5?
      Are there some limitations on this solution?
  • We are looking into using InvokeWo​rk flow to replace RunWorkFlow from TeamFoundation Build Activities
    3 Posts | Last post March 19, 2012
    • RunWorkFlow does support invoking other work flows but without parameter support.
      We are going to try to use InvokeWo​rkflow within one TeamFoundationServer Build process template to launch another TeamFoundationServer Build process template but with the added capability of passing parameters.
      Have you worked with that team at all or do you think it will work?
    • I have not tried it with TFS but I expect it will work correctly.  
    • For some reason it won't work correctly with TFS.  To start with you have to modify the Microsoft.Activities.Extensions assembly to include a Fake Activity.  Without it a build controller won't load the assembly and will fail with Can't create type.
      Public sealed class FakeActivity : CodeActivity
      This will allow your controller to read the Assemblies, but seems to continue to fail with:
      Cannot cancel the workflow. Agent needs to be restarted. Details: The operation could not be performed because WorkflowApplication a174b332-587f-495f-bc21-ed256655ba90 is aborted.
      I have an open forum request for help on this..
  • How about hosting this in web project
    2 Posts | Last post February 03, 2012
    • Thanks for the example.
      I tried to implement this in my web hosted xaml workflow but I just can't seem to set the local assembly path right.(It throws "Could not find file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\ChildWF.dll'").
      I guess I need to supply the virtual path for this case, tried System.Web.HttpContext.Current.Server.MapPath("~/ChildWF.dll") but didn't work.
      Had you tried doing that and do you have any idea what am I missing?
    • Ok, finally I got it working.
      Should had used 
  • How about using this solution with WF services
    2 Posts | Last post October 27, 2011
    • Thanks for this example and the explanation.
      I trying to create service that invokes child activity based on a request. 
      Request contains assembly and name of a child activity. A child activity contains Send and Receive activities and should be part of this service. When it invokes the exception appear:
      System.InvalidOperationException: Activity 'InitializeCorrelation' must be used in a WorkflowServiceHost.
         at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
         at Microsoft.Activities.Statements.InvokeWorkflow.EndExecute(AsyncCodeActivityContext context, IAsyncResult asyncResult)
         at System.Activities.AsyncCodeActivity`1.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result)
         at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
      As I understand at this moment this solution does not support services or I made something wrong.
    • The child workflow is run with WorkflowInvoker which does not support messaging activities.  If you can deploy the child activity as a XAMLX file when you want to invoke it just send a message to it.
  • Is it possible to make InvokeMethod work from the child XAML?
    3 Posts | Last post September 23, 2011
    • I've played with the sample for LoadAndInvokeWorkflow, and it works fine (no surprise). This activity has the potential to help us out a *lot*...if we can resolve one issue. 
      I added a simple class to the project called SquareNumber that has one method: 
      public static in SquareIt(int num) {return num*num;}
      I can add an InvokeMethod activity (passing TheNumber) to the InvokeChild.xaml prior to the LoadAndInvokeWorkflow and it works fine. However, if I put the same activity (passing Num) in the Increment.xaml following the Assign, I get an exception saying it can't create a TargetType (see exception snippet below). Is there something I need to to in order to be able to use InvokeMethod? Without that capability, LoadAndInvokeWorkflow loses a lot of its value for us. Anything you can do to help would be greatly appreciated...Thanks, Glenn.
      Unhandled Exception: System.Xaml.XamlObjectWriterException: Failed to create a 'TargetType' from the text 'local:SquareNumber'. ---> System.Xaml.XamlParseException: Type reference cannot find type named '{clr-namespace:InvokeChildWorkflow}SquareNumber'.
         at MS.Internal.Xaml.Context.ObjectWriterContext.ServiceProvider_Resolve(String qName)
         at MS.Internal.Xaml.ServiceProviderContext.System.Windows.Markup.IXamlTypeResolver.Resolve(String qName)
         at System.Xaml.Replacements.TypeTypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
         at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateObjectWithTypeConverter(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value)
         at MS.Internal.Xaml.Runtime.ClrObjectRuntime.CreateFromValue(ServiceProviderContext serviceContext, XamlValueConverter`1 ts, Object value, XamlMember property)
         at System.Xaml.XamlObjectWriter.Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter`1 typeConverter, Object value, XamlMember property, String targetName, IAddLineInfo lineInfo)
    • The problem is that the assembly is defined in the local: namespace.  I need to modify the code so that you have a way to set the local assembly.
    • With Microsoft.Activities v1.8.7 we now have full support for overriding LocalAssembly and loading third party libraries. The sample has been updated to demonstrate this - take another look.