- Workflow Foundation Tutorial: Part 1 – Introduction
- Workflow Foundation Tutorial: Part 2 – The Basics
- Workflow Foundation Tutorial: Part 3 – Project Setup
Before we get heavy into the code I think it’s important we go over exactly what Workflow Foundation is, why you would want to use it and some of the vocabulary used.
What is Workflow Foundation?
Workflow Foundation is a Microsoft technology built into the .NET Framework to give developers a declarative way to model the “flow” of their application. WF also includes APIs for handlling long running workflows as well as the ability to “rehost” the designer inside your custom application to give you an extreme amount of flexibility in building your workflows. WF was first introduced with .NET 3.0 and completely overhauled in .NET 4.
Why would I use Workflow Foundation?
- Humans are naturally visual communicators and a lot of times it’s easier to describe complex ideas through visual imagery.
- One of the hardest part of the development process is not writing code. It’s communicating across a wide range of people in different disciplines to learn and understand what exactly we’re building.
- This is why the whiteboard has become the Roesetta stone of developers and business people. Business people don’t always understand the code and developers don’t always understand the business vocabulary but we can both understand lines and boxes drawn a whiteboard.
- Workflow gives you this same capability except you’re not showing an abstract 2nd hand representation of the code’s implementation of the process, you’re showing the actual code!
- This makes it much easier to communicate and can help head off confusion earlier in the process.
- You can even bring up a blank workflow and start dropping code activities on the designer to create a rough outline of what you’re going to build.
- It just makes complex processes easier to understand.
It naturally lends it self to testability.
- The smallest component of a Workflow is a Code Activity.
- Each activity should do one thing and one thing only and you can write Unit Tests around them.
- Code Activities pass data in and out of them through arguments which makes it extremely easy to Mock.
- On top of that Workflow includes it’s own Service Locator pattern called “Workflow Extensions” which we’ve found to be easy to implement and efficient.
- The next step up is the Workflow itself.
- We tend to group all the activities for a particular process into a Workflow. For example in order processing we would group all the taxation related activities like checking if the customer was taxable, determining if we need to apply any special logic for particular tax scenarios.
- We can write integration tests that test just this taxation workflow.
- Just like Code Activities, Workflows have arguments that you can pass data into and get data out of so we can easily mock.
- This can greatly speed feedback from tests because you don’t have to wait on external dependencies. An example is our order processing system.
- Next we group these workflows into a main Workflow, commonly the Workflow hosting our service. We can then have our automated regression suite test the service from end to end.
- The smallest component of a Workflow is a Code Activity.
It’s great for long running processes.
- Combined with AppFabric you can have long running processes which can spin up and spin down as necessary. This means you can make more efficient use of your resources since when a Workflow isn’t running it’s state is preserved in the database and only processing at the moment an event causes it to reinitialize.
It’s built into the .NET Framework
- There are no frameworks to download and install. It’s just there.
- It’s built on some of Microsoft’s core battle-tested technologies like WCF and XAML.
- You don’t have to go in whole hog. On existing apps you can identify a process you want to replace with Workflow and start from there. Workflows can be invoked from your existing code.
You’re not “locked in.”
- If for some reason you decide you want to move away from Workflow you have a visual guide of how your processes are built and all your code activities are written in C#.
For a more in-depth review of why I think you might want to use Workflow Foundation in your solution, check out my appearance on .NET Rocks
Next, let’s go over some of the vocabulary of Workflow Foundation.
|Activity||A unit of program behavior in Windows Workflow Foundation. Single activities can be composed together into more complex activities.|
|Activity Action||A data structure used to expose callbacks for workflow and activity execution.|
|Argument||Defines the data flow into and out of an activity. Each argument has a specified direction: in, out, or in/out. These represent the input, output, and input/output parameters of the activity.|
|Bookmark||The point at which an activity can pause and wait to be resumed.|
|Compensation||A group of actions designed to undo or mitigate the effect of previously completed work.|
|Correlation||The mechanism for routing messages to a workflow or service instance.|
|Expression||A construct that takes in one or more arguments, performs an operation on the arguments and returns a single value. Expressions can be used anywhere an activity can be used.|
|Flowchart||A well-known modeling paradigm that represents program components as symbols linked together with directional arrows. In the .NET Framework 4, workflows can be modeled as flowcharts using the Flowchart activity.|
|Long-running Process||A unit of program execution that does not return immediately and may span system restarts.|
|Persistence||Saving the state of a workflow or service to a durable medium, so that it can be unloaded from memory or recovered after a system failure.|
|State Machine||A well-known modeling paradigm that represents program components as individual states linked together with event-driven state transitions. Workflows can be modeled as state machines using the StateMachine activity.|
|Substance||Represents a group of related bookmarks under a common identifier and allows the runtime to make decisions about whether a particular bookmark resumption is valid or may become valid.|
|Type Converter||A CLR type can be associated with one or more System.ComponentModel.TypeConverter derived types that enable converting instances of the CLR type to and from instances of other types. A type converterr is associated with a CLR type using the System.ComponentModel.TypeConverterAttribute attribute. A TypeConverterAttribute can be specified directly on the CLR type or on a property. A type converter specified on a property always takes precedence over a type converter specified on the CLR type of the property.|
|Variable||Represents the storage of some data that must be saved and accessed later.|
|Workflow||A single activity or tree of activities invoked by a host process.|
|XAML||eXtensible Application Markup Language|
David Chappell Chappell & Associates April, 2009 Download this article Everybody who writes code wants to build great software. If that software is a server application, part of being great is scaling well, handling large loads without consuming too many resources.
In my next post we will build out our project and start writing some code!