BizTalk and Configuration Files
In one of my previous post I mentioned Log4Net. Configuration of log4net is done through a registry pointing to a configuration file, where one can determine how configuration of logging inside BizTalk for instance can be done. So using a config file for configuration purposes in BizTalk is also possible in another way. One can create an environmental variable by going to control panel --> system --> advanced.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrPmlVJBuIU6OzjwxeX3lT1ztFl0LZXQ6UB7UHm3tppGjeW4ZWg35aVyxfqImMDdsCh13aCBOdUu5Ef6iHswI1sdyizF2EgVHmXQziFF-10MvImgPQVx-IAAy3HbT831J5KR_M/s400/Environmental+Variables.bmp)
Next one can create an new enviromental variable by clicking enviromental variables and new button under system variables.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbgtr03PIC2_GGzlzcQFU8JL8DLE69fdwQNfNwt3j9fwYgCm3XezIB0cgARzBABMZb7gQVUj0Sy5w2PKT814n0nR66qcAajmvTDD12Vph8wO_g0zZ38VtbhrbEkFpgkR41NdeT/s400/Environmental+Variables+2.bmp)
After creating the variable it can be checked by using the command prompt and type : set enviromental variable.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0JNTPdIbjcdzz-WUElMsacCh-8tgGgvTcrUfUJHYumjXlFY18WC-Qir5Mw6iXXBSUUxwBrn2BB2iPjqOoV593NYT4iCH74U4AhQcT_KimtBZ8-XCuQJRUAypr1bbLyfBr1Tdp/s400/Environmental+Variables+3.bmp)
Once this is al done a class library can be added to a BizTalk solution. In class module the following assemblies are necessary:
#region Using
using System;
using System.Xml;
using System.Text;
using System.Reflection;
using System.Configuration;
using System.Collections.Generic;
using System.IO;
#endregion
namespace xxx.Components
{
///
/// BizTalk Helper Class
///
[Serializable]
public class HelperClass
{
///
/// Get values from configuration file (app.config)
///
/// Key string
///return value as object
public object GetConfigValue(string key)
{
// Get the application configuration file path.
// Combining location of config file with name of config file
string exeFilePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("The Created Environmetal Variable"),"ConfigFileName");
// Log filepath
System.Diagnostics.EventLog.WriteEntry("CREATE", exeFilePath);
// 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
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(configFile,
ConfigurationUserLevel.None);
// Log value
System.Diagnostics.EventLog.WriteEntry("CREATE In",config.AppSettings.Settings[key].Value.ToString());
// Return desired value from configuration file
return config.AppSettings.Settings[key].Value.ToString();
}
}
}
Only hardcoded names will be in used in the combine methode of the System.IO.Path. Compared to log4net a registry key will read for the location of the config file. This is as mentioned a different approach in reading in a config file inside a BizTalk Solution. The reason I needed the config file was to put credentials for dynamic file send port, which where different in development, test and production environment. Below you see code used in a message assign shape:
//SET PATH (SHARE)
NewProjectMsg_FILEPort(Microsoft.XLANGs.BaseTypes.Address) = "file://\\\\"+ serverName + "\\" + directoryName + "\\" + guid + ".xml";
//Set Location
newProjectMsg.LOCATION = serverName;
//Set message properties for file
newProjectMsg(FILE.CopyMode) = System.Convert.ToUInt32(helper.GetConfigValue("FileCopyMode"));
newProjectMsg(FILE.Username) = System.Convert.ToString(helper.GetConfigValue("Username"));
newProjectMsg(FILE.Password) = System.Convert.ToString(helper.GetConfigValue("Password"));
Hopefully this usefull to anyone or maybe there is a better way. The latter I am interested in, so please comment if you do.
Technorati:
BizTalk 2006
Configuration Files
Log4Net
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrPmlVJBuIU6OzjwxeX3lT1ztFl0LZXQ6UB7UHm3tppGjeW4ZWg35aVyxfqImMDdsCh13aCBOdUu5Ef6iHswI1sdyizF2EgVHmXQziFF-10MvImgPQVx-IAAy3HbT831J5KR_M/s400/Environmental+Variables.bmp)
Next one can create an new enviromental variable by clicking enviromental variables and new button under system variables.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbgtr03PIC2_GGzlzcQFU8JL8DLE69fdwQNfNwt3j9fwYgCm3XezIB0cgARzBABMZb7gQVUj0Sy5w2PKT814n0nR66qcAajmvTDD12Vph8wO_g0zZ38VtbhrbEkFpgkR41NdeT/s400/Environmental+Variables+2.bmp)
After creating the variable it can be checked by using the command prompt and type : set enviromental variable.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0JNTPdIbjcdzz-WUElMsacCh-8tgGgvTcrUfUJHYumjXlFY18WC-Qir5Mw6iXXBSUUxwBrn2BB2iPjqOoV593NYT4iCH74U4AhQcT_KimtBZ8-XCuQJRUAypr1bbLyfBr1Tdp/s400/Environmental+Variables+3.bmp)
Once this is al done a class library can be added to a BizTalk solution. In class module the following assemblies are necessary:
#region Using
using System;
using System.Xml;
using System.Text;
using System.Reflection;
using System.Configuration;
using System.Collections.Generic;
using System.IO;
#endregion
namespace xxx.Components
{
///
/// BizTalk Helper Class
///
[Serializable]
public class HelperClass
{
///
/// Get values from configuration file (app.config)
///
/// Key string
///
public object GetConfigValue(string key)
{
// Get the application configuration file path.
// Combining location of config file with name of config file
string exeFilePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("The Created Environmetal Variable"),"ConfigFileName");
// Log filepath
System.Diagnostics.EventLog.WriteEntry("CREATE", exeFilePath);
// 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
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(configFile,
ConfigurationUserLevel.None);
// Log value
System.Diagnostics.EventLog.WriteEntry("CREATE In",config.AppSettings.Settings[key].Value.ToString());
// Return desired value from configuration file
return config.AppSettings.Settings[key].Value.ToString();
}
}
}
Only hardcoded names will be in used in the combine methode of the System.IO.Path. Compared to log4net a registry key will read for the location of the config file. This is as mentioned a different approach in reading in a config file inside a BizTalk Solution. The reason I needed the config file was to put credentials for dynamic file send port, which where different in development, test and production environment. Below you see code used in a message assign shape:
//SET PATH (SHARE)
NewProjectMsg_FILEPort(Microsoft.XLANGs.BaseTypes.Address) = "file://\\\\"+ serverName + "\\" + directoryName + "\\" + guid + ".xml";
//Set Location
newProjectMsg.LOCATION = serverName;
//Set message properties for file
newProjectMsg(FILE.CopyMode) = System.Convert.ToUInt32(helper.GetConfigValue("FileCopyMode"));
newProjectMsg(FILE.Username) = System.Convert.ToString(helper.GetConfigValue("Username"));
newProjectMsg(FILE.Password) = System.Convert.ToString(helper.GetConfigValue("Password"));
Hopefully this usefull to anyone or maybe there is a better way. The latter I am interested in, so please comment if you do.
Technorati:
Comments