Execute Static Method with BizTalk Business Rules Engine

This week, I needed to use Business Rules in my BizTalk Development. Indeed, I currently develop some flow using the ESB Toolkit 2.1 on BizTalk Server 2010.  Because, I try to use pure messaging flow, I need to invoke some special function in the business rules to get current date time with specific formating.

For example, I need to create a file with the following name : OutputFile_yyMMdd_HHmmss.txt, I can’t use the BizTalk Port Macro, because I use a specific datetime.

So I decide to use a static function to get this date :

namespace BusinessRulesVocabularies 
{
  public class Vocabularies
  {
    public static string GetNow() 
    {
        System.Diagnostics.Trace.WriteLine("Entering GetNow Vocabularies"); 
        return (DateTime.Now).ToString("yyMMdd_HHmmss"); 
    } 
  } 
} 

After adding your assembly to the GAC, you’ve access to this one in the Business Rule Composer, in the fact explorer, in the .Net Class section :

image

right click on the .Net Assemblies and click on browse :

image

You will see all you assemblies in the GAC.

image

after, you’ve have access to the “STATIC METHOD” (with or without parameter) of your class, so you can drag & drop your method on the IF or THEN pane.

When you test your rules, maybe you can see that nothing happens… this is probably because your platform is not properly set.

You can see on the msdn that the behavior of the rule engine is not good for you :

By default, the rule engine requires you to assert an instance of a .NET class to execute a policy that invokes a static member of the .NET class

So according to this page you have two solutions to allows the execution of Static class without assert an instance :

  • insert a registry key StaticSupport under HKEY_LOCAL_MACHINE\Software\Microsoft\BusinessRules\3.0 (in Wow6432node on a 64-bit machine)
  • add the StaticSupport in the BTSNTSVC[64].exe.config

the second solution consist in the following snippet to add in the config file  :

<configuration>
    <configSections>
        <section name="Microsoft.RuleEngine" type="System.Configuration.SingleTagSectionHandler" />
    </configSections>
    <Microsoft.RuleEngine
        UpdateServiceHost="localhost"
        UpdateServicePort="3132"
        UpdateServiceName="RemoteUpdateService"
        CacheEntries="32"
        CacheTimeout="3600"
        PollingInterval="60"
        TranslationTimeout="3600"
        CachePruneInterval="60"
        DatabaseServer="(localhost)"
        DatabaseName="BizTalkRuleEngineDb"
        SqlTimeout="-1"
        StaticSupport="1"
    />
</configuration> 

 

more details on the msdn page

And if you choose to add the configuration in the config file, don’t forget to also add this configuration in the configuration file of the Business Rule Composer (located in : C:\Program Files (x86)\Common Files\Microsoft BizTalk\Microsoft.RuleComposer.exe.config)

Enjoy Clignement d'œil

This entry was posted in BizTalk, English and tagged , . Bookmark the permalink.

Leave a comment