Answered by:
how to invoke the Microsoft Business Rules Engine Remotely?

Question
-
Hi,
Can anybody kindly tell, how to invoke the Microsoft Business Rules Engine Remotely?
Like I've a standalone .NET application(out side of BizTalk server envt),
which wants to use the MS BRE. So how to call/execute a policy programmatically from a m/c (where MS BRE is not installed) to another m/c where MS BRE is installed and a rules Policy is deployed.
Thanks & Regards,
KKanavia- Edited by K Kanavia Wednesday, July 8, 2009 5:25 AM
Wednesday, July 8, 2009 5:23 AM
Answers
-
Hi All,
I tried something on my own.
I found that, from local m/c .NET application, MS BRE rules (deployed on other m/c) can be invoked. (by getting access to the BizTalkRuleEngineDb database and connecting to it to get latest rules deployed).
Following are the steps (for accesing the database)
and after that is the code segment to actually connect to database and invoke rule engine.
Steps:
1. The DLLs used in MS BRE Composer(on remote m/c) and used on local m/c(to pass facts) should use
the same <GACKey>.snk (key) for building the DLLs.
2. On both m/cs these DLLs sould be added in GAC using gacutil command.
3. A windows domain user should have access to BizTalkRuleEngineDb (where bz rules are stored from MS BRE remote m/c).
e.g my domain user id DOMAINx/k.kanavia (a domain id), is given permissions as dbo, db_owner, public
to SQL Server = <server m/c name>/<database server name> and to database = BizTalkRuleEngineDb on remote m/c.
(This uses Windows Authentication mechnism to access SQL Server database.)
Code segment to invoke MS BRE rules remotely. (this to be used in local .NET application)
//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 = <createFacts>;
//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);
//*** here rules will be executed and updated facts will be returned, which can be used further in your application ***
This solves remote invocation of MS BRE rules quest, by one way. There could be other ways.
Thanks & Regards,
KKanavia- Marked as answer by K Kanavia Thursday, August 13, 2009 10:17 AM
Thursday, August 13, 2009 10:17 AM
All replies
-
Hi,
The BRE comes with an API which allows you to access it from .Net code. You could write a simple webservice which internally uses the BRE api. You deploy this webservice on the machine hosting the BRE and call the webservice methods from the remote machine.
There are a lot of samples on the internet that explain how to use the BRE API. Just google or bing :-)
HTH, Randal van Splunteren - http://biztalkmessages.vansplunteren.net - Please mark as answered if this answers your question.- Proposed as answer by Thiago Antonio Brancher de AlmeidaEditor Wednesday, July 8, 2009 8:56 PM
- Marked as answer by Andrew_ZhuModerator Wednesday, July 15, 2009 2:00 AM
- Unmarked as answer by K Kanavia Thursday, August 13, 2009 10:17 AM
Wednesday, July 8, 2009 7:30 AMModerator -
BRE has an API which you can call in .NET to access BRE features like vocablaries etc. But this works on the same server where the BRE is installed because it works under the BizTalk framework and the framework uses the database(BizTalkRuleEngineDb) to retreive the BRE vocablaries and policies.
Abdul Rafay http://abdulrafaysbiztalk.wordpress.com/ Please mark this answer if it helpsWednesday, July 8, 2009 7:40 AM -
http://msdn.microsoft.com/en-us/library/ms952922.aspx
Thank You RaghuRam Nadiminti
Software Development Engineer
BizTalk TeamMonday, July 13, 2009 5:45 AM -
Hi All,
I tried something on my own.
I found that, from local m/c .NET application, MS BRE rules (deployed on other m/c) can be invoked. (by getting access to the BizTalkRuleEngineDb database and connecting to it to get latest rules deployed).
Following are the steps (for accesing the database)
and after that is the code segment to actually connect to database and invoke rule engine.
Steps:
1. The DLLs used in MS BRE Composer(on remote m/c) and used on local m/c(to pass facts) should use
the same <GACKey>.snk (key) for building the DLLs.
2. On both m/cs these DLLs sould be added in GAC using gacutil command.
3. A windows domain user should have access to BizTalkRuleEngineDb (where bz rules are stored from MS BRE remote m/c).
e.g my domain user id DOMAINx/k.kanavia (a domain id), is given permissions as dbo, db_owner, public
to SQL Server = <server m/c name>/<database server name> and to database = BizTalkRuleEngineDb on remote m/c.
(This uses Windows Authentication mechnism to access SQL Server database.)
Code segment to invoke MS BRE rules remotely. (this to be used in local .NET application)
//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 = <createFacts>;
//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);
//*** here rules will be executed and updated facts will be returned, which can be used further in your application ***
This solves remote invocation of MS BRE rules quest, by one way. There could be other ways.
Thanks & Regards,
KKanavia- Marked as answer by K Kanavia Thursday, August 13, 2009 10:17 AM
Thursday, August 13, 2009 10:17 AM -
Hi,
Nice solution. Be aware though that you're using part of BizTalk run time and assemblies on the local machine. Additional BizTalk licences might be needed. Also this is not in line with your original question in which you state:
...call/execute a policy programmatically from a m/c (where MS BRE is not installed) to another....
In this case the MS BRE is (partly installed) (by copying over dlls).
HTH, Randal van Splunteren - http://biztalkmessages.vansplunteren.net - Please mark as answered if this answers your question.Thursday, August 13, 2009 10:25 AMModerator -
Hi,
Well said Randal,
it requires Microsoft.RuleEngine.dll(only) in references of local application. (I forgot to mention, thanks Randal)
But it does not require any biztalk rule engine dll or any other biztalk dll.
And does not require installation of MS BRE on local m/c.
About licensing,
yes it needs to be inquired how to use the dll on local m/c.
Thanks & Regards,
KKanaviaThursday, August 13, 2009 10:41 AM -
Hi Kanavia,
We have followed the same method. as you mentioned above. It is connecting to Remote BRE and I could see RuleSets. But the Policy is not triggering. When we call
RulesEngine.Execute(doc1);
After execute When we use doc1.Document.OuterXML; is not returning validated xml.
Can you explain how to debug this issue.
Thanks
-RaviFriday, December 4, 2009 10:58 AM -
Hi Kanavia,
Could you please reply for the above issue.
Thanks
-RaviTuesday, December 8, 2009 7:48 AM -
Hi,
Did you try to test the policy in the BRE composer tool? You can right click a policy in this tool and click test. You can then add a test instance xml message to test the policy.
When the policy works in the BRE composer you should focus on your BRE installation and configuration. I must say though that I still think the described way of using the BRE is not recommended. (See my above posts).
When the policy test failes you need to look at the policy and rules inside it to find the cause of your problem.
HTH, Randal van Splunteren - http://biztalkmessages.vansplunteren.net - Please mark as answered if this answers your question.Tuesday, December 8, 2009 8:48 AMModerator -
Hi Randal,
Thanks for your response. I have tested my Policy and used the same method in the machine where I have BRE Composer Tool Installed. It is working fine.
but when I am trying to execute the Same method using the Microsoft.RuleEngine.dll(only) in references of local application and call from remote, It failed.
Can you suggest what kind of Configuration settings we need to do for BRE installation to make Remote BRE Execute Method Call.
Thanks
-RaviTuesday, December 8, 2009 9:20 AM -
Hi,
I'm not a fan of the described way of calling the BRE. IMHO the only supported and best way of doing this either:
- Install the BRE locally and connect to a remote BRE database.
or
- Wrap the BRE api in a web service so that you call the webservice to execute the policy on the remote machine.
So I would suggest to follow one of the above mentioned methods.
HTH, Randal van Splunteren - http://biztalkmessages.vansplunteren.net - Please mark as answered if this answers your question.- Proposed as answer by Raja.Kumaravel Tuesday, December 8, 2009 9:32 AM
Tuesday, December 8, 2009 9:29 AMModerator