Revision #15

You are currently reviewing an older revision of this page.
Go to current version

Introduction

There are a couple of options a developer can have when comes to using configurable values. These options can be divided into two categories:

  • File: BTSNTSvc.exe.config, Custom config file, Enterprise Library
  • Database: Business Rule Engine, SSO, or Custom database
  • Registry

This article will provide guidance on each of possible options.

BTSNTSvc.exe.config file

The BizTalk orchestration engine uses an XML file called BTSNTSvc.exe.config to determine certain behaviors. This file attaches to the main executable BTSNTSvc.exe. Any changes placed in BTSNTSvc.exe.config apply to all host instance regardless of their names. This file is always located in the same directory as the BTSNTSvc.exe file, which is usually C:\Program Files\Microsoft BizTalk Server 2010. Any changes in this file will result in a restart of BizTalk Host Instance. Values can be obtained through code in expression shape in an orchestration.

//Get Configuration parameters from BTSNTsvc.exe.config
BTSNTsvcConfigValue1=System.Configuration.ConfigurationSettings.AppSettings.Get("Value1");
BTSNTsvcConfigValue2=System.Configuration.ConfigurationSettings.AppSettings.Get("Value2");

Blogs

Custom Config File

A custom configuration file (.config) can be option to store configuration data that you can use within BizTalk orchestration for instance. A custom config can be easier to maintain that BTSNTSvc.exe.config file.You can choose whether or not to use Enterprise Library or custom code. Enterprise Library may be too much overhead to just access a custom file. Accessing a .config file can be done using simple .NET code, using the System.Configuration namespace.

        /// <summary>
        /// Return configuration value
        /// </summary>
        /// <param name="key">Key in configuration</param>
        /// <param name="nameConfigFile">Name of configuration file</param>
        /// <returns></returns>
        public static string GetConfigValue(string key, string nameConfigFile)
        
{
            
// Get the application configuration file path.
            // Combining location of config file with name of config file
            string exeFilePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("BizTalkConfigOptions", EnvironmentVariableTarget.Machine), nameConfigFile);

            
// Map to the application configuration file.
            // Instantiate ExeConfigurationFileMap
            ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();

            
// Bind filepath to configFile object
            configFile.ExeConfigFilename = exeFilePath;

            
// Instantiate Configuration object and assign configFile
            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);

            
// Return desired value from configuration file
            return config.AppSettings.Settings[key].Value.ToString();
        
}

When using custom config file in a multimachine environment you need to maintain config on each machine.

Registry

Another option is accessing the registry to obtain configuration values. Through custom code in .NET Helper Class using Microsoft.Win32 namespace you can access the registry and read values. See code below to access the registry.

[Serializable]
   
public static class REGISTRYConfigHelper
   
{
       
/// <summary>
        /// Return value from registry
        /// </summary>
        /// <param name="subKey">subKey in the Hive</param>
        /// <param name="value">Value from subKey</param>
        /// <returns>Request value from the subKey</returns>
        public static string Read(string subKey, string value)
       
{
           
// Create value variable
            string retValue = null;

           
// Opening the registry key
            RegistryKey rk = Registry.CurrentUser;

           
// Open a subKey as read-only
            RegistryKey sk1 = rk.OpenSubKey(subKey,RegistryKeyPermissionCheck.ReadSubTree,System.Security.AccessControl.RegistryRights.FullControl);

           
// If the RegistrySubKey does exist
            if (sk1 != null)
           
{
               
try
               
{
                   
// If the RegistryKey exists get its value or null is returned.
                    retValue = (string)sk1.GetValue(value.ToUpper());
               
}
               
catch (Exception e)
               
{
                   
System.Diagnostics.Trace.WriteLine(e.Message);
                   
throw;
               
}
           
}

           
// Return value
            return retValue;
       
}

   
}

Storing values in registry is an option, however it is not easy to maintain. In a multiple machine BizTalk deployment this is far from ideal option as you have to maintain multiple registries. The same accounts for using custom file or BTSNTSvc.exe.config.

Business Rule Engine

So far registry and file options have been discussed. Not the best options when you want to consider a central store for your custom configuration data. A database would be a better option from an administrative viewpoint. Business Rule Engine (BRE) can be used to store configuration data. Using a vocabulary with custom definitions containing constant values.  Code below shows how to access custom definition in a vocabulary.

        /// <summary>
        /// Obtain value from Defition in a Vocabulary
        /// </summary>
        /// <param name="definitionName">Definition Name e.g. Value1</param>
        /// <param name="vocabularyName">Name of Vocabulary i.e. Config</param>
        /// <returns>Return Constant Value</returns>
        public static string Read(string definitionName, string vocabularyName)
        
{

            
// RuleStore Object
            RuleStore rlsRuleStore;
            
// Vocab Info collection
            VocabularyInfoCollection vicVocabInfo;
            
// Vocab itself
            Vocabulary vocVocab;

            
// Provides the default deployment driver used to import, export, deploy, un-deploy, and 
            // set tracking configuration for published rule sets and vocabularies, 
            // and to retrieve their deployment characteristics.  
            RuleSetDeploymentDriver rsdDriver = new RuleSetDeploymentDriver();

            
// The current RuleStore
            rlsRuleStore = rsdDriver.GetRuleStore();
 
            
// Set Vocabulary based on Vocabulary collection
            vicVocabInfo = rlsRuleStore.GetVocabularies(vocabularyName, RuleStore.Filter.All);

            
// Get the vocabulary itself
            vocVocab = rlsRuleStore.GetVocabulary(vicVocabInfo[0]);

            
// Get the definition
            VocabularyDefinition vocDef = vocVocab.Definitions.GetByName(definitionName);

            
// Set LiteralDefition
            LiteralDefinition literalDefinition = vocDef as LiteralDefinition;

            
// Return Value
            return literalDefinition.Value.ToString();
        
}

    
}

SSO Database

Content to be added.

Custom Database

Content to be added.

Samples

There are a couple of samples available demonstrating the options:

See Also

Content to be added.


Revert to this revision