Archive for the ‘WF’ Category

In the last post we have discussed at length about different mechanisms of parameter passing and obtaining results from a workflow.In this post we will discuss about another extremely important aspect of workflow and host communication i.e. Bookmarks. Bookmarks as the name suggests is a like Bookmark for a book. When created at a particular point in the execution of the workflow , the execution is suspended and the workflow waits to be resumed.When a bookmark is resumed it starts executing exactly from the same point.


Workflow host is an application responsible for executing the workflow and managing different workflow lifecycle events like start, completion, idle, unloaded etc.Now the workflow host should be capable of exchanging information with the workflow. This information exchange can be broadly categorized into:

a) The parameters/arguments needed to start the workflow and to get the results back after workflow has executed.

b) The intermediate data needs at different stages of a long running workflow (e.g. when the workflow is waiting for a specific input like Manager’s Approval).

In this post we will concentrate on the different mechanisms of parameter passing and getting results back. In the subsequent posts we will move into more complex scenarios related to long running workflows.

WF 4.0 provides two classes for hosting and managing the workflows System.Activities.WorkflowInvoker and System.Activities.WorkflowApplication.WorkflowInvoker provides a simple model to execute the workflow like a method call whereas WorkflowApplication much greater flexibility to execute and manage the workflow instance. To start with we will explore the different mechanisms to pass data back and forth using WorkflowInvoker and WorkflowApplication.


In my last post I had written about the Rule Engine that comes embedded with Windows Workflow Foundation and in this post I will show how we can use this with the PolicyActivity.

The System.Workflow.Activities.PolicyActivity class is a specialized workflow activity class that encapsulates a RuleSet.The PolicyActivity.RuleSetReference property maintains reference to a RuleSet stored in a .rules file.During execution time the PolicyActivity retrieves the rules from the .rules file and execute the rules.

The demo that I have prepared implements a very simple rule to calculate discount, based on order value,if order value is > 100 and < 200 then discount is 10% and if > 200 then 20%.


Workflow Foundation Rule Engine – Part I

Posted: March 15, 2009 in WF

In my post on Business Rules and Rule Engine I have explained about Business Rules,Business Processes and what actually a Rule Engine does.In this post I will be discussing about the Rule Engine that comes with Windows Workflow Foundation(WF).

First let us explore the important classes related to Rule Engine and how they provide abstraction for the various components required for rule processing.All the classes are present within the namespace System.Workflow.Activities.Rules.

  • Rule – This class represents a Rule which is nothing but an if-then-else construct.So each Rule is composed of a condition and associated if-then and else actions.Rule class has the properties
    • Condition – This property is of type RuleCondition.This is the base class and actual implementation is provided by the RuleConditionExpression class.This class represents a condition as System.CodeDom.CodeExpression.The list of expression supported by WF is listed in MSDN
    • ElseActions/ThenActions – These are collection of type RuleAction.RuleAction is an abstract base class and actual implementation is provided by the classes:
      • RuleStatementAction – Modifies a property or calls a method.
      • RuleHaltAction – Halts the execution of the RuleEngine and returns the control to the calling code.
      • RuleUpdateAction – This class is used to indicate that a rule is updating a variable on which other rules are dependent.This causes reevaluation of the dependent rules.
  • RuleSet – This is a collection of Rule objects.
  • RuleEngine – This evaluates the RuleSet via it’s Execute method.

Now let’s quickly summarize the basic flow operation for the WF Rules Engine:

  • We have to define the RuleSet and associated Rules using Visual Studio 2005/2008.We can develop our WinForms application as well to create/edit the rules.The basic functionality of RuleEditor is exposed by the class System.Workflow.Activities.Rules.Design.RuleSetDialog.We can invoke this UI from our own application very easily.I will discuss about this in more details along with WF Rules Externalization.
  • The RuleSet editor create the RuleSet objects in memory and finally serialized and stored in some persistence storage.Visual Studio Editor stores them in .rules files.The structure of the .rules files is as shown below.Note how closely it resembles the object model we have discussed above.
  • <RuleDefinitions xmlns=””>
        <RuleSet Name=”SampleRuleSet” ChainingBehavior=”Full” Description=”{p3:Null}” xmlns:p3=””>
            <Rule Name=”SampleRule” ReevaluationBehavior=”Always” Priority=”0″ Description=”{p3:Null}” Active=”True”>
                <RuleExpressionCondition Name=”{p3:Null}”>

  • During execution time these .rules files are read and the RuleSet object is deserialized from xml data.The RuleEngine then executes and evaluates the RuleSets

In my next post I will explain with examples how we can use RuleSet along with PolicyActivity of WF.