Windows Workflow Foundation in .NET4

Windows Workflow Foundation (WF4) in .NET 4 is designed to make it easier for new developers to learn, addresses a wider range of customer scenarios, and is more efficient. 

WF is a programming model for composing application logic and coordinating execution, allowing developers to abstract complicated code while leveraging a set of runtime services.  Activities are the building blocks that are composed together to build workflows.  The runtime provides the ability to save the state of the workflows, track information about the workflow, and manage the coordination of multiple workflows executing at the same time.

Design your Workflow

Visual Studio 2010 represents a significant update to the WF design experience.  Performance and extensibility have been dramatically improved, and the designer surface has an improved, WPF-based look and feel.

The new designer has significant productivity enhancements for authors composing large workflows, including the ability to expand and collapse child activities, a breadcrumb trail along the top of the designer that allows users to drill in and out of deep workflows, and better visualization capabilities to discover and address validation errors.

Designer features 

The workflow designer in WF4 is a WPF control that you can use to host the designer within your custom applications with a few lines of code. This allows you to create a custom workflow-editing experience within your application and allows your users to visualize an executing workflow within your applications. 

Introducing Flowchart: The New Control Flow Style

WF4 introduces a flowchart style of control flow, which allows you to create flexible workflows that require the ability to loop back to previous steps, as well as skip steps based on conditions within the workflow.  This is coupled with new tooling that allows for flowcharts to be constructed visually. The new flowchart control flow in WF4 allows for business logic to be composed in a way that feels more natural to the workflow author and in a way that is more visually compact.  Below, the flowchart style is used to build a hiring process workflow.


Hiring process workflow 

A Simplified Activity Model

At the heart of WF is the authoring of custom activities for use in higher-order workflows, and WF4 makes creating custom activities easier than ever. WF4 dramatically reduces the amount of code that developers need to write to implement custom application logic for a variety of scenarios. As the activity model has been simplified, the performance of the runtime has dramatically increased.

The way activities are authored has also been updated to provide options that are optimized for specific scenarios, supplying a variety of activity base classes that enable the developer to make the authoring experience only as powerful or complex as required.  The activity model also supports asynchronous execution, allowing a workflow to compose and coordinate multiple concurrent branches of asynchronous logic.  In addition, the model now includes an ActivityAction feature, which enables you to write an activity that can be customized by offering the consumer of your activity the ability to plug in type-safe callbacks for custom logic.  This would, for example, allow you to create a ProcessOrder activity that allows the consumer to provide their implementation of HandlePayment.  

Building a Workflow

To demonstrate WF, let’s construct a workflow to retrieve the syndication feeds from a number of blogs.  Here we will build a workflow that will use a GetWebPage custom activity to retrieve a number of feeds in parallel.  Additionally, we use the CompletionCondition of the ParallelForEach in order to stop retrieving feeds once half of the requests have completed.  This lets my workflow move forward once the first half of requests are successfully processed (and gracefully handle cancelling the other outstanding requests).

Blog workflow 

Now that we’ve built the workflow, we can incorporate it into an ASP.NET MVC application.  Here we’ll use the WorkflowInvoker to execute the workflow from a controller. 

public ActionResult GetBlogs()


    var results = WorkflowInvoker.Invoke(

        new GetSomeBlogs(),

        new Dictionary<string, object>



                "Urls", new List<string>









    var feeds = results["Feeds"] as List<SyndicationFeed>;

    ViewData["Message"] = "You received " +

                          feeds.Count.ToString() +

                          " feeds with a total of " +

                          feeds.Sum(feed => feed.Items.Count()) +

                          " posts.";

    return View("Index");


Workflows and WCF Services

As we talked with customers, we found that many were interested in using WF with services to compose and coordinate messaging in their application.  In .NET 4, we set out to make it easy to use workflows with services to compose and coordinate messaging by integrating WF with Windows Communication Foundation (WCF).  

WF comes with messaging activities that allow you to expose service operations as part of the workflow, and can be used to enable fine-grained control over the way inbound messages are correlated to workflow instances.  Additionally, you can use WorkflowServiceHost to host your services within IIS7 and Windows Server AppFabric, eliminating the need to write custom hosting logic. If you are writing a workflow that uses web services to communicate, WorkflowServiceHost frees you from writing an application around your workflow service.  WorkflowServiceHost and the workflow runtime will ensure workflows are automatically persisted and restarted when needed, with the correct state information loaded.  The runtime addresses the complexities of managing the resources and state of the workflow, including managing the flow of transactions into and out of the workflow.   

Find Out More

Visit the WF MSDN Dev Center and the Endpoint team blog to learn more, or connect with the Workflow team on the MSDN forums.  To get started with Workflow Foundation, check out following whitepapers: The Workflow Way: Understanding Windows Workflow Foundation and A Developer’s Introduction to WF4.


Comments (24)

  1. Fred Morrison says:

    You neglect to mention that none of WF4 is available for use in SharePoint 2010 workflows, which is still stuck with WF3.

  2. Hi Soma!

    WF4 is great stuff. But why force us (C# developers) to use VB expressions in the designer? It seems very awkward when working in a purely C# environment except for the expressions in the WF designer. Any way of configuring WF4 to use C# expressions instead?

  3. Basant Singh says:

    I worked with Workflow (Beta .Net framework 3.0) approx 2.5 yrs back. But it was a bit confusing & finally we re-worked the application. Let’s hope WF in .Net 4 is easier to implement.

  4. Holystream says:

    Forcing developers to use VB expression in the designer sucks.  I hate it.

  5. Usama Khalil says:


    i working on an HRMS application. and i want to ask

    can i use the workflow services with ORACLE 11g.

    and if not then how can i use that for my workflow activity persistence.


  6. danieldsmith says:

    Just want to echo what others are saying re the VB expression syntax.  This *SUCKS* big time.

  7. Tom says:

    VB was never a proper languauge… and continues to be a second choice even though Microsoft evangelists tout it and push it

  8. Ever tried to teach a business process modeller these fine points of c#’s obligatory syntactic sugar?

    A = DateTime.Now  <- field/property access

    B = A.ToString() <- parameterless function, that is a property

    C = o.SomeFunction(0) <- an integer parameter

    D = o.SomeArray[0] <- an array index, i.e. an integer parameter

    E = "c:/a/b/c/d.txt"

    F = @"c:abcd.txt"

  9. Seems WF 4 is finally done right

  10. mwinkle says:

    Usama Khalil,

    Out of the box, we have an implementation of our persistence features that target SQL Server. If you wanted to target Oracle for workflow services, you would need to provide an implementation of the instance store that would handle writing to the database.   There’s a very basic file based InstanceStore implementation in the PurchaseProcess sample in the WF SDK.


  11. stevescottwork says:

    I cannot for the life of me find any documentation on how to implement a long running workflow…So for example My flow would email 4 people, and wait for all 4 to respond (persist to a DB?) before continuing on to (for example) email another 4 people…so like an approval process

    The documentation for "Hello World" instant flow is allover the place

    Help!  I want to sue this so bad 🙂

  12. mwinkle says:

    Regarding the use of VB expressions throughout workflow, we’re actively investigating and working with the C# team to incorporate this into a future release.  A little bit of background can be found in the two "Future of…" talks at PDC08 that Anders and Paul did on C# and VB.  Currently, VB was able to let us use an in-memory compiler, which is the technology we rely on in order to enable expressions.  

    We had a fair amount of feedback from WF3 customers that they wanted the ability to have a more expressive way to do data binding between activities, which led us to making the decision to add expressions in the WF4 release.  This enables much greater flexibility when interacting with data in the workflow.  We currently have the VB compiler available which is why WF4 uses VB expressions everywhere.  

    If you have more questions, or feedback on this, please feel free to email me.

    –matt winkler

    –pm, wf team

    –mwinkle at microsoft dot com

  13. mwinkle says:


    We have a couple of samples which show a similar process to what you are asking for:

    HiringProcessRequest sample: This shows using WorkflowServiceHost and the messaging activities

    Purchase Process sample: This uses WorkflowApplication as the host

    There are two good intro docs as well

    Getting Started :

    Windows Workflow Foundation Programming:

    Let me know if that helps!

    –matt winkler, pm wf team

  14. Sambo says:

    Where are the VS 2010 RTM bits? They should be up on MSDN by now.

  15. phuff says:

    Sambo, VS2010 will be available at launch on April 12th.

    Polita Paulus


  16. Sambo says:

    phuff: I’ve never seen a version of VS (or really any MS software) that wasn’t RTM’d and available on MSDN weeks before the launch date.

    How could you possibly dup the media, etc, in time?


  17. xiaopywsp says:


    This enables much greater flexibility when interacting with data

    Monogram MulticolorMonogram Mini Lin

    Damier AzurTaiga LeatherEpi Leather

    Monogram CanvasGraffittiSuhali Leather

    Seasonal CollectionMonogram GlaceNomade

    Damier CanvasDamier GraphiteMahina

    Monogram DenimMonogram Perforation

    Monogram VernisDamier Geant Canvas

    Monogram Miroir

  18. LouisVuittonstory says:

    I’m definitely happiest. The support we receive from our loved ones is priceless. But let me tell you what money does help with.

  19. Thank you very much, I am closely following your site really give much useful information

  20. BRiddle says:

    I am still new to .Net workflow.  We were planning to use WF3.5 in a new app in which workflows must include both ASP.Net page navigations and non-human code activies and alternate between the two types of activities in a single flow.  That app must be scalable to 30,000 users.   With the recent release of WF4, we wanted to use the new paradigm to leverage the claimed better performance.   But the scalable WF3.5 examples we found and tested used classes and techniques not now part of WF4.   So we looked at the WF4 sample solutions that included ASP.Net interactions.

    For this, I found the WF4 "Hiring Process" sample useful.  But in trying to understand the concepts changes between WF3 and WF4, that sample has one behavior that puzzles me.

    The sample app seems to work on my workstation, but I’m having trouble understanding the ResumeRequestService project.  When it starts, it launches a web page request to the default page of the VS2010 web server which shows nothing but a directory listing of the project home directory.   Given that it seems to be nothing but a declarative web service, I don’t see how showing a web server’s default page helps or is required.  (The other service, HiringRequestService, is hosted by console application).   When I use ProcessExplorer to see how that project’s ResumeRequestService assembly DLL is tied into the behavior, Process Explorer shows that no process on my machine currently has that DLL.

    Why is that project hosted in a web server rather than in a comand prompt?   Why is the project configured to show the default web page rather than no page at all?  What would be the analog for this sitation in a "real" WF4 ASP.Net-related workflow?

    Thank you for clearing this up for newbie.

  21. Leon Welicki says:

    @Briddle – Thanks for trying the sample!

    The ResumeRequestService runs in the Visual Studio Development Server. One of the goals of this sample is to show how to host services both in a console app and in a web server. Deploying your service to a web server / AppFabric is a major scenario for workflow services. You can find more details on workflow services here and a video on deploying workflow services to AppFabric here

    Regarding the page with the directory listing, that page is opened by VS when the service project is executed and, as you mentioned, it is not required (though is a good learning tool since users can click on ResumeRequestService.xamlx). You can prevent that page to show by going to the properties of ResumeRequestService project -> Web -> Start Action and select "Don’t open a page…".

    The readme for this sample available at contains more details on how to setup and execute the sample (and also features and scenarios for the sample)

    Please let me know if this helps, if you still have questions feel free to email me at lwelicki at microsoft dot com.

    — Leon Welicki

    — PM, WF

  22. Bowsil Ameen says:

    Thank You that was really interesting

  23. Tortured By VB Insanity says:

    Just seeing the datatype VisualBasicValue<T> causes stomach cramps and triggers a bad case of my Fight-or-flight response.

  24. <a href="">seslisohbet</a> says:

    VB was never a proper languauge… and continues to be a second choice even though Microsoft evangelists tout it and push it

Skip to main content