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:
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!