A workflow is a series of activities involved in a task or set of activities collectively forms a work. Except for the first and last step, steps will have a preceding and succeeding step.
Windows Workflow Foundation provides a very nice graphical interface to create the activities involved in a workflow. Windows Workflow Foundation is a great technology for creating workflows and can be used in combination with different technologies, like SharePoint, WCF, ASP.NET etc. Windows workflow foundation comes with a set of commonly used activities packaged along with it. They will be available in the Toolbox and you can just drag and drop them to your workflow. You can create your own custom activities and make them available in the Toolbox as well.
A workflow model when compiled, it can be executed inside any Windows process including console applications, forms-based applications, Windows Services, ASP.NET Web sites or Web services. Since a workflow is hosted in a process, a workflow can easily communicate with its host application. Though we use graphical interface to desgin workflows, they are storedsas XAML markup. A sample workflow will look like this:
- <Activity mc:Ignorable="sads sap sap2010" x:Class="BMIRuleEngine.Workflow1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" .......................................... .......................................... .......................................... <x:Members>
- <x:Property Name="BMIInput" Type="InArgument(x:Double)" />
- <x:Property Name="Recommendation" Type="OutArgument(x:String)" /> </x:Members>
- <sap2010:ExpressionActivityEditor.ExpressionActivityEditor>C#</sap2010:ExpressionActivityEditor.ExpressionActivityEditor>
- <sap:VirtualizedContainerService.HintSize>1350,572</sap:VirtualizedContainerService.HintSize>
- <mva:VisualBasic.Settings>Assembly references and imported namespaces for internal implementation</mva:VisualBasic.Settings>
- <If sap:VirtualizedContainerService.HintSize="1310,532">
- <If.Condition>
- <InArgument x:TypeArguments="x:Boolean">
- <mca:CSharpValue x:TypeArguments="x:Boolean">BMIInput < 18.5</mca:CSharpValue>
- </InArgument>
- </If.Condition>
- <If.Then>
- <Assign sap:VirtualizedContainerService.HintSize="242,60">
- <Assign.To>
- <OutArgument x:TypeArguments="x:String">[Recommendation]</OutArgument>
- </Assign.To>
- <Assign.Value>
- <InArgument x:TypeArguments="x:String">["Your BMI is less than 18.5. You are Underweight. You should try adding some muscle mass through regular exercises."]</InArgument>
- </Assign.Value>
- </Assign>
- </If.Then> .......................................... .......................................... .......................................... </If>
- </Activity>
Windows Workflow Foundation can be used in following types of scenarios but not limited to this:
- Applications with User-interface page flows.
- Workflows that are document-centric.
- Human workflows.
- Service-oriented applications wtih composite workflows.
- Rule-driven workflows for business.
- Workflows for systems management.
workflow framework can be used or are useful in the following situations:
- For creating business rule engines. This may include simple rules, such as if-then-else decisions based on an input argument to more complex rules, such as the potentially large set that is a combination of several other rules.
- Case where maintaining state for the workflow's lifetime is needed. For example, if the employee who is in charge of approving a task is on leave for a week, the task should be bookmarked or stored for use at a later point of time and should be able to continue the workflow. The bookmarked or stored task should be able to re-activate when required.
- Interactive applications that connect with people. For example, if an HR must approve some policy documents, the workflow must be able to display a user interface or communicate to the HR through other software.
- Changing workflow behavior like changing a condition or editing an action which are common use cases.
- Multiple applications that work together. For example, a workflow rule engine gets input from an ASP.NET web application and does workflow activities and call another application for generating a travel request.
- Monitoring of a running workflow and examining its execution in real time.
- Support for graphical user interface tools for creating workflows easily. A workflow consists of different steps or activities and we should be able to re-use the activities if we create one.
What is Activity?
An activity defines a piece of work. The work an activity implements can be very simple or it can be quite complex. Activities are the fundamental building blocks or unit of a workflow. An activity represents an action in a workflow. They can be added to a workflow either programmatically or using graphical design interface where you can drag and drop activities. The workflow instance is completed only when all the activities in a given flow path are finished. An activity can perform a single action, such as writing a value to a database, or it can be a sequence of activities. Many of the activities in the base activity library, such as IfElse, Sequence, and While, are composite activities.
An activity, like a workflow, can be sequential, which means that the order of its actions is specified at design time. Or the activity can be event-driven, which means that the order of its actions is determined at run time in response to external events.
Windows Workflow Foundation contains a library of standard activities and provides the mechanisms for you to create your own. This enables extensibility and reusability between workflows.
Windows Workflow Foundation (WF) includes default activities that provide functionality for communication with applications and services, control flow, state management, event handling, and conditions. However, we might need a custom activity in most scenarios to implement specific behavior of our application or workflow.
Windows Workflow Foundation (WF) API's will help you to create custom activities. Custom activity can be created by using code or using graphical user interface.
How to create an Activity?
For creating a custom activity using code, you need to define a custom activity class that either derives directly from the activity, or from a default activity that derives from activity. Custom activities by default, display within the workflow designer as an empty rectangle with the activity’s name. To provide a custom visual representation of your activity in the workflow designer, you must add the required functionality to the activity. You can combine existing activities together to form a new composite activity.
Using the graphical Activity Designer tool is the easiest way to create an activity. As we have already mentioned, activities can also be created directly in code. Like a workflow, an activity is just a class. Each activity can have events that it responds to, and properties containing its state.
- using System.Workflow.ComponentModel;
- public class SampleActivity: Activity {
- ...
- ...
- }
Windows Workflow Foundation Rules Engine
Windows Workflow Foundation (WF) introduces rule capabilities to the .NET Framework development platform. Rules creation ability extend from simple conditions to complex rulesets executed by a full-featured forward chaining rules engine.
The rules capability allows for the declarative modeling of application units which can be easily created and plugged into the overall business process. Rules capability allow us to model the application in a way which can be easily modified without affecting the other parts of the application. Sample scenarios for rules engine technology are lab result analysis system, promotion enforcement fare calculation, inventory management etc.
Rules and Conditions
Conditions are logic that return true or false. A number of Work Flow activities work based on conditions by affecting their behavior. These activities include the While activity, the IfElseBranch activity, and the ConditionedActivityGroup. The IfElseBrach activity, for instance, executes the Then part, if condition evaluates to true otherwise executes the Else part. We can implement conditions in code, or in XML.
Rules contains various conditions with a set of actions to perform. Rules use a declarative if-then-else style, where the "if" is a condition to evaluate. There are substantial differences between rules and procedural code. Procedural code in most applications, changes the flow of the control based on the condition. In case of rules, execution engine evaluates the logic and invoke their actions.
The third term, "rule set" is a collection of one or more rules.
Creating a Rule Activity and Consuming it using an MVC application
Step 1 Create an ASP.Net MVC Application
- Open Visual Studio2017
- Go to File->New->Project.
- Select Web ASP.NET Web Application.

Step 2 Create a Model
- Right click on Models folder
- Choose -> Add -> Class
- Give name as BMI and add the below code to the class
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- namespace SampleWorkOutSolution.Models {
- public class BMI {
- [Display(Name = "Heigh in metre")]
- public double Height {
- get;
- set;
- }
- [Display(Name = "Weight in Kilogram")]
- public double Weight {
- get;
- set;
- }
- [Display(Name = "BMI")]
- public double BMIValue {
- get {
- // Avoiding DivideByZero exception
- if (Height > 0) {
- // BMI = Weight (in Kg) / Height (in metre) Square
- return Weight / (Height * Height);
- } else {
- return 0;
- }
- }
- }
- public string Recommendation {
- get;
- set;
- }
- }
- }



Rashmi SharanPosted Aug 8, 2020, 3:50 AM
I am getting issue in step 7.Please help
seshalatha gPosted Jul 28, 2019, 7:04 AM
Can you please explain step 7 in detail as the above steps as it is a little bit confusing
Diana Quesada HidalgoPosted Mar 14, 2019, 8:07 AM
Hi , I have problem with WorkflowInvoker. when I build, this message appears "The name 'WorkflowInvoker' does not exist in the current context". Do you have the project for download? I need help because I believe in step 7 I got confused.
Ram Vinay KumarPosted Jul 20, 2018, 7:18 AM
While I was implementing this workflow with MVC, I was getting error, due to console application. But when I changed it to "Activity Library", I was able to use the workflow service at MVC end. So, don't create Console, just create Library.