Using the Business Rules Engine to pass parameters to orchestrations

A new policy
Condition that is always true
Add some parameters to the list
The ArrayList class is in mscorlib assembly
Calling the policy
The parameters have to be cast to right types

A while ago I was developing an orchestration for an integration project where the requirement was to route messages to a remote system based on an ID found in the message. If the ID in the message was found on a predefined list, the message was routed, otherwise the message was discarded.

There is nothing unusual in this on itself, but the catch here was that the list of accepted IDs was going to be changing constantly in the future. If I hardcoded the list in to the orchestration assembly, I would have to rebuild and redeploy the assembly every time changes were made to the list. Also setting up an SQL Server database for the accepted IDs and querying it with SQL adapter every time the orchestration ran seemed a bit overkill.

The Business Rules Engine that ships with BizTalk Server 2006 R2 can be used to get parameters for orchestrations fairly easily. You don't have to specify any messages or schemas and the parameters are fetched with one orchestration shape. Also, no rebuilds or redeploys are needed when the parameters change. The parameters are passed in a single ArrayList object.

1. Launch the Business Rule Composer, add a new policy and add a new rule for that policy. The name of the policy will be visible in the orchestration designer, the name of the rule doesn't matter.

2. Add some condition that is always true to conditions of the rule, for example "1 is equal to 1". This way the Actions part of the rule is always executed.

3. The parameters are set in the Actions part of the rule. This is done by using the ArrayList.Add method. You can add integers, floats, strings or boolean values, even in the same list. Pay attention to the order of the elements in the list because the elemets are accessed according to their indexing in the orchestration.

You can add the ArrayList.Add method calls to the rule from the .NET Classes tab of the Facts Explorer. Select the Browse... item from the right-click menu of the .NET Assemblies folder. The ArrayList class can be found from mscorlib assembly.

4. Deploy the policy by first selecting Publish from the right-click menu of the version and then selecting Deploy.

5. Add a variable of type ArrayList to the orchestration. Add a Call Rules shape and pick the right policy from the dropdown list and your ArrayList variable as the parameter. The variable has to be initialized before the call (you can set the Use Default Constructor property of the variable to True). After the Call Rules shape, the ArrayList variable contains the data defined in the Actions part of the rule.

6. By default the parameters in the ArrayList are treated as generic Objects. You have to cast them to strings to actually use them. If you need parameters of some other type, you can use the parse methods of the appropriate .NET classes. If you just want to see if the list contains some string (like I did in my integration project), you can use the ArrayList.Contains("string to look for") method.

7. The policy is updated by creating a new version of it and deploying it as was done in step 4. The Rule Engine always uses the latest version of the policy.

2010-07-01 Kalle Huttunen

BizTalk® and SQL Server® are registered trademarks of Microsoft Corporation.