BizTalk and Configuration Files

Posted: July 17, 2007  |  Categories: BizTalk 2006 Uncategorized
Tags:

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.

Next one can create an new enviromental variable by clicking enviromental variables and new button under system variables.

After creating the variable it can be checked by using the command prompt and type : set enviromental variable.

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:

Author: Steef-Jan Wiggers

Steef-Jan Wiggers is all in on Microsoft Azure, Integration, and Data Science. He has over 15 years’ experience in a wide variety of scenarios such as custom .NET solution development, overseeing large enterprise integrations, building web services, managing projects, designing web services, experimenting with data, SQL Server database administration, and consulting. Steef-Jan loves challenges in the Microsoft playing field combining it with his domain knowledge in energy, utility, banking, insurance, healthcare, agriculture, (local) government, bio-sciences, retail, travel, and logistics. He is very active in the community as a blogger, TechNet Wiki author, book author, and global public speaker. For these efforts, Microsoft has recognized him a Microsoft MVP for the past 8 years.

BizTalk360
BizTalk Server

Over 500+ customers across
30+ countries depend on BizTalk360

Learn More
Serverless360
Azure

Operate efficiently with enterprise-grade Azure monitoring,
tracing, remediation & governance in one platform

Learn More

Back to Top