Calling the BRE Remotely from .NET

It seems that the BRE comes up a lot in my work with BizTalk these days, which is why I’ve written some articles about its use.  In one article, I discuss how to call the BRE from .NET. The code in this article works very well when calling a local BRE installation, but we don’t address how to achieve the same goal when calling an instance of the BRE on another server. One ETM reader asked me about this (thanks, Gautam) which led me to an MSDN post by K Kanavia:

http://social.msdn.microsoft.com/Forums/en/biztalkgeneral/thread/373dd01a-2140-4327-affe-27a33ad77976

The approach in the article is to more explicitly use pieces of the BRE API that identify the server rather than to accept the default which is to use the local engine. This approach is detailed in the code below:

//Get the SqlRuleStore from BizTalkRuleEngineDb database on remote m/c
//pass on correct databaseserver and database name
Microsoft.RuleEngine.RuleSetDeploymentDriver rdd =
    new RuleSetDeploymentDriver(RuleEngineDatabaseServer,
    RuleEngineDbName);

SqlRuleStore sqlRuleStore =
    (SqlRuleStore) rdd.GetRuleStore();

//Get access to RuleSetInfoCollection for the policy,
//pass on the policy name
RuleSetInfoCollection rsic = sqlRuleStore.GetRuleSets(policyName,
    RuleStore.Filter.All);

//Create a RuleSet object based on the rule set information
RuleSet rs = sqlRuleStore.GetRuleSet(rsic[0]);

//Create the RuleEngine object
engine = new RuleEngine(rs);

//create facts here
Object[] facts = ;

//if u want to catch the debug info from MS BRE execution.
if (debugRulesEngine)
{
    dti = new DebugTrackingInterceptor(@rulesEngineDebugFile);
    engine.TrackingInterceptor = dti;
}

//Execute the policy by invoking RuleEngine.Execute method,
//passing on the facts
engine.Execute(facts);

Thanks to K Kanavia for posting this code on MSDN!

Advertisements

About Ed Jones

Ed is a Connected Systems and .NET Specialist for RBA in the Twin Cities. Contact Ed

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: