OdeToCode IC Logo

New Article on Windows Workflow Rules and Conditions

Friday, September 1, 2006

If you only look at one feature in Windows Workflow, look at the Policy activity. The Policy activity processes rules. Business rules, game rules - any type of declarative knowledge. Read more in the latest OdeToCode article - "Windows Workflow - Rules and Conditions".

The Policy activity is easy to use, and provides a boatload of functionality out of the box. You can prioritize rules, and track rule processing in detail. WF provides an API to modify rules at runtime, which provides a great deal of flexibility. Rules execute with forward chaining semantics, meaning the rules engine analyzes the dependencies and side effects of each rule, and can reevaluate rules when the underlying data changes. I can see applications using Windows Workflow solely for the Policy activity.

More Workflow articles on OTC:
Hello, Workflow - an introduction.
Authoring Workflows - a look at XAML, XOML, and Workflow compilation.
The Base Activity Library - a tour of the out-of-the-box activities in WF.
Hosting Windows Workflow - a look at using the persistence, scheduling, tracking, and transaction services in WF.

csaxton Saturday, September 30, 2006
Great article on the WWF Rules engine. I am curious how one would implement a rule that is applied to a collection of items, something akin to "IF request.Payments[n].Amount > 10000 THEN request.Payments[n].RequiresApproval = true"

scott Monday, October 2, 2006
DJL Friday, October 6, 2006
Great article...thanks.
I have created a xoml file containing several custon activities, in addition to an IfElse activity. In the ifelse, I wish to write a rule that involves the value of one of the other activities in the workflow. Because this is a xoml based workflow, there are no class attributes in the file, so I am prevented from writing a conditional rule such as...
ActivityA.AccountBalance == 1000.
Upon closing the rules editor, I am told that the rule is invalid. How do I get around this for xoml-based workflows?
scott Saturday, October 7, 2006
DJL: It sounds like activity binding is the solution for you, though I would have to see the code to be sure.

Create a dependency property on your custom activity that binds to the value in the other activity (Activity=ActivityA, Path=AccountBalance). Then your condition can use the local property on your activity.
Rory Primrose Friday, December 1, 2006
Thanks for the article. Is it possible that one rule in a ruleset can enable or disable another rule in the set?

I have a set of rules that need to check an object chain for null references. If the chain goes object.object.Nullable<int>, I need to check that both objects exist and that the int != null before running a rule against the int value. If any of the rules fail, the other rules need to be disabled to avoid a null reference exception.

I guess I could add more conditions to each rule to check the values of each point in the chain, but that seems heavy handed.

RulesReader Friday, January 12, 2007
Excellent article. Very thorough and complete! Impressive work.
Gravatar Murali Saturday, April 3, 2010
Thanks for this wonderful article.

How to execute a Ruleset through code? I have a Ruleset defined in the Policy activities through RuleDefinitions. I have tried a sample code, but getting the Rule validation failed error as the object attributes used in the condition is not accessible in code. Any idea?

Code snippet:
// Deserialize from a .rules file.
XmlTextReader rulesReader = new XmlTextReader(fileName);
WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
ruleDefinitions = (RuleDefinitions)serializer.Deserialize(rulesReader);
ruleSet = ruleDefinitions.RuleSets[0];

Thanks in advance!
Gravatar Camilo Maldonado Friday, September 3, 2010
Hi Scott, thank for the article. It's so good.
In this momento i got a problem with the deploy of a proyect that use windows workflow.
The problem is this.
We have two environments, depelopment and production.
When i build the solution in my computer, the workflow works correctly. But when i used the Team Foundation to depoly the application in production environment, the workflows fails.
This is the problem

System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: The workflow failed validation.

I implemented a WorkflowValidationFailedException and the problem is that and this is the error
WorkflowValidationFailedException[error 1342: Activity 'SaldoCreditoExisteT' validation failed: Can not find the condition "cndCalcular"

Then, i disassembled the two dlls and i compared and find one difference.

The rule file name, that is in resources folder, is diferent.
In the dll that works the name is

and in the dll that fails the name is

We use TFS and i am sure that the versio it's the same.

can you tell me please why this is happend??

any ideas will be appreciated.

thanks in advance
Comments are closed.