I have found very little documentation on how to pass facts into a Call Rules shape (i.e. make a call to the Microsoft Rules Engine) in a BizTalk 2004 orchestration.
There are 3 things that can be passed into a Call Rules shape:
- A message whose fully qualified .NET type matches a schema that is used in your Business Rule Policy.
- A Microsoft.RuleEngine.DataConnection
There is an SDK example of using a Fact Retriever, but that is only for caching data (long term facts). If you want the rules engine to perform a live query you must pass a Data Connection to it at run time (short term facts).
- An instance of any .NET type that is used in your Business Rule Policy. (we won't cover this in this post, but I may come back to this in a later post.)
Let's start with passing a message into the Rules Engine. Firstly, it is absolutely critical that you note the Fully Qualified Name of your schema. You will find it in the properties of the schema file in your BizTalk project...
The Business Rules Composer UI will not know the fully qualified name, and unless you type it in you will not be able to pass an instance of the correct message into the Policy.
Once you have browsed to your schema in the Business Rules Composer, you MUST prefix the Document Type with the .NET namespace of the schema (NOTE, this is not the XSD target namespace of the schema!) This is what is should look like after you have matched it to your schemas fully qualified .NET type name:
Then, in the Orchestration designer, you need to create a variable of the same type, like so...
Only when there is a match between the Document Type in the Rule Composer and the Fully Qualified .NET Type of the schema in BizTalk, will a message of that type appear when you configure the Call Rules shape. Like in this example:
Now lets look at passing a Data Connection in.
If you have used a Data Connection in your Business Rule by browsing to a data source like in this example:
If you want to pass a Data Connection to your Call Rules shape, the trick is to declare a variable of type Microsoft.RuleEngine.DataConnection (dcNorthwind) (as well as a SQLConnection variable, con)
Then, in an Expression Shape, configure the DataConnection, like so...
sCon = "Initial Catalog=Northwind;Data Source=(local);Integrated Security=SSPI;";
con = new System.Data.SqlClient.SqlConnection(sCon);
dcNorthwind = new Microsoft.RuleEngine.DataConnection("Northwind", "ShipperCountry", con);
(As an aside, here's a challenge for you. See if you can get BizTalk to read the connection info from a config file! This is harder than you might think. See this article for part of what's involved. I will post an example later.)
Then this variable will appear in the list when you configure your Call Rules shape:
That's it. It seems simple enough, I suppose. But it took me hours to figure this out without any proper documentation. I'm not sure why the BizTalk 2004 documentation is so lacking.
One other thing to note: You don't necessarily need to use a Call Rules shape to make a call to the Rules Engine. You can build up a call in an Expression Shape like in this example. The tricky thing is if you wanted to pass more than one fact in, you need to pass in an array of objects. Unfortunatley the XLANG/s language that is used in these Expression shapes does not support arrays very well. (See this article by Charles Young for more info about this) Later, I will try and put together an example with a workaround.
posted on Saturday, December 04, 2004 5:16 PM