July 29, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Using a SectionHandler for Painless BizTalk 2004 Configuration

  • March 23, 2006
  • By Jeffrey Juday
  • Send Email »
  • More Articles »

Putting It All Together

In the sample code, all of the Custom SectionHandler functionality is captured in a class called DataSetSectionHandler. As stated earlier, to implement the IConfigurationSectionHandler interface, add the Create function as in the example below.

public object Create(
   object parent,
   object configContext ,
   System.Xml.XmlNode section)
{
   Load (section);

   return _myDataSet;
}

The Create function returns an object to the code calling the ConfigurationSettingsGetConfig function. Populating the DataSet is done in the Load function. The Load function appears below.

public void Load ( XmlNode section )
{
   XmlReader xmlRead;

   xmlRead = new XmlNodeReader(section);

   _myDataSet = new DataSet();

   _myDataSet.ReadXml(xmlRead,XmlReadMode.InferSchema);

}

The Readxml function populates the DataSet with XML data and metadata. For optimal performance, online help recommends setting the XmlReadMode to be reflective of the data you are loading. In your solution, you're loading XML without an included Schema.

One consideration mentioned earlier was to include the capability to refresh changes to the config file in running code. One quirk of the configuration file information is, once the file is loaded, the information is cached. The following code is a workaround for the cache issue.

public void Refresh()
{
   _myDataSet.Dispose();

   _myDataSet = null;

   Load (FindNodeSectionInCurrentConfig());
}

Now, look at how to invoke the DataSetSectionHandler.

Using DataSetSectionHandler

DataSetSectionHandler controls access to the encapsulated DataSet object. Once the data is loaded, you use the GetSettingValue* functions to retrieve the data from the DataSet. Thus, you can skirt the array limitation of the BizTalk Expression icon.

Also, by controlling creation of the DataSet, a class inheriting from DataSetSectionHandler can choose to update the DataSet data before returning data back to the invoking code. So, for example, you can call the refresh function each time you invoke a property in a class inheriting from DataSetSectionHandler.

When deploying the DataSetSectionHandler on your BizTalk server, remember to copy the SectionHandler assembly to the C:Program FilesMicrosoft BizTalk Server 2004 directory.

Using the DataSet was not the only solution under consideration. DataSet seemed to fit all of the criteria.

Alternatives

Here is a summary of the alternatives, along with a short explanation of why the alternatives didn't fit all solution criteria.

Two alternatives were evaluated, the XmlSerializer object and a Typed DataSet.

The XmlSerializer allows a developer to Serialize the contents of a class into XML data or Deserialize XML into an instantiated class. You can use XmlSerializer to call DeSerialize and, violà, a class is populated with the data from the section in the config file. There are two limitations with this approach:

  • You still need to create a separate class for each config section.
  • Automatically refreshing the data would have been difficult to implement.

The second option, a Typed DataSet, showed promise until you use the Typed DataSet in the BizTalk Expression Icon. Typed DataSet members are accessed through arrays. As stated earlier, you cannot access arrays in the BizTalk Expression. The array limitation may not exist in BizTalk 2006 (currently in beta).

Conclusion

Configuration is often the last consideration on a BizTalk project, but important to providing something extra to support administration. A SectionHandler is perfect for organizing all of your configuration information. With the help of a DataSet reading and refreshing, XML configuration of data can be easy.

Download the Code

You can download the code that accompanies this article here.

Sources

Application Configuration Files Explained: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet04222003.asp





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel