Validating BizTalk and AppDomain Configuration

One of my company’s Client has a huge BizTalk Infrastructure and there are lot of orchestrations in different projects and each orchestration has it’s own AppDomain as per their standard and configuration of each AppDomain is contained within another configuration file which have configurations like Application Blocks settings, Cache Settings etc and if this configuration is invalid or location path is incorrect it cause biztalk host to stop

Following is an example of one such configuration within BizTalk Config.

<AppDomainSpecs>

<AppDomainSpec Name=”ABC.IHUB.Orchestrations” SecondsIdleBeforeShutdown=”-1″ SecondsEmptyBeforeShutdown=”12000″>

<BaseSetup><ConfigurationFile>D:\ABC.ProcessMerge.Orchestrations.dll.config</ConfigurationFile></BaseSetup>

</AppDomainSpec>

</AppDomainSpecs>

Above example has just one app domain. Consider having 100+ AppDomains and if there is problem in one configuration it would take a lot of manual effort to find issue in the configuration. We actually faced this issue. We were afraid of even thinking of checking all configurations manually so we wrote a utility validate the configuration to some extent. We will keep on updating this utility to make it more robust like one feature I was thinking that it should validate against configuration schema that could be pretty useful as well. Anyways below is the code for the utility

Code of the Utility

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Xml;

using System.IO;

namespace BTSConfigValidator

{


class Program

{

static string CurrentFile = string.Empty;

static string Errors = string.Empty;

static void Main(string[] args)

{

if (args.Length <= 0)//checking if commandline param exists

{

Console.WriteLine(“Commandline Parameter Missing …”);

Console.WriteLine(“Please enter valid path of BiztalkNTSvc.exe.config”);

}

else if (!File.Exists(args[0]))//checking if BiztalkNTSvc file exists

{

Console.WriteLine(“Please enter valid path of BiztalkNTSvc file ..”);

Console.WriteLine(args[0]);

}

else

{

XmlDocument btsConfig = new XmlDocument();

btsConfig.Load(args[0]); //loading configuration in XML document

XmlNodeList nodes = btsConfig.SelectNodes(“//AppDomainSpec/BaseSetup/ConfigurationFile”); // selecting app domain nodes

XmlReader validator = null;

XmlReaderSettings settings = new XmlReaderSettings();

//setting XML validator configuration

settings.CheckCharacters = true;

settings.CloseInput = true;

settings.ConformanceLevel = ConformanceLevel.Document;

settings.IgnoreComments = true;

settings.ValidationType = ValidationType.DTD;

try

{

foreach (XmlNode node in nodes)//loop through each app domain

{

CurrentFile = node.InnerXml;//loading path of appdomain configuration file

validator = XmlReader.Create(CurrentFile, settings);

while (validator.Read()) //reading XML file to validate

{

} validator.Close();

}

if (string.IsNullOrEmpty(Errors))

Console.WriteLine(“All Configuration Files are valid found no Exception”);

else

{

Console.WriteLine(“Found Few Exceptions Please see detail”);

Console.WriteLine(Errors);

}

}

catch (System.IO.DirectoryNotFoundException dnf)

{

Console.WriteLine(“Following file is not found Please check the Path…”);

Console.WriteLine(CurrentFile);

}

catch (System.IO.IOException ioe)

{

Console.WriteLine(ioe.ToString());

}

catch (Exception ex)

{

Console.WriteLine(“Exception in following file Please check detail…”);

Console.WriteLine(“File Name:- “ + CurrentFile);

Console.WriteLine(“Exception Message :- “ + ex.Message);

if (validator != null)

if (validator.ReadState != ReadState.Closed)

validator.Close();

}

}

Console.WriteLine(“Press Enter to Exit…….”);

Console.ReadLine();

}

}

}

Advertisements

XPath to Filter values from XML Document

Below XPath might come in handy when you want to remove some unwanted values from you entire XML document.

 

//*[text()='(NULL)’]

 

“//*” statement selects all nodes from XML Document

“[text()='(NULL)’]” statement checks the node selected by above statement for text “(NULL)” if nodes text is equal to this criteria it is returned

 

You can add your namespace as well to the statement.

//*[text()='(NULL)’ and namespace-uri()=’http://soap.microsoft.com/schemas/%5D

Also, you could join search statements as well to filter multiple values

//*[text()='(NULL)’ or text()=’false’ or text()=’CA’]

GAC Multiple Files from Command line

We had faced an interesting issue while using windows 2008 Servers. It does not seem to have windows explorer view to GAC. We used to update dll’s in GAC by simply dragging & dropping files, I don’t know if Microsoft has removed “Assembly” tool but it used to be very simple even if you had 100 dlls. Anyways there is command line way to GAC’ing multiple files.

Following is the code to GAC files on command line.

for /f %f in (‘dir /b *.dll’) do gacutil /if %f

 

above command is simply a foreach loop on result of command “dir /b *.dll” and this command list all dlls in the current directory and last part of command after “do” statement is “gacutil /if %f” which actually executes gacutil command with ‘i’,’f’ switch to install file in GAC who’s filename is contained within “%f” variable.

That’s it all your files contained within the current directory will go in GAC instantaneously

About Me

My Name is “Wajhi Ghumman”

I have three Passions

  1. Vintage Motor Bikes
  2. Adventure
  3. Lots and Lots of Coding, whether it’s Javacript, C#, Ruby, Objective C, Jave, XLang, ASP.NET MVC, Biztalk Orchestration etc I Love them all.

I am currently a solution architect at Xavor. I have been in field of Software Development & Design from Last 8-9 years professionally. I have worked in Web App Development (MVC, JSP, ASP.NET), Windows App Development, Middleware component development, Enterprise Application Integration, Socket Programming, Mobile App Dev (Andriod, IPhone) etc.

I have created my blog to share some of the knowledge that I have gained in the field and I hope to write some useful blogs that would actually makes someone’s work little bit easier.

Wajhi Ghumman

De-serialization Issue

I just faced an issue while de-serializing a XML file to specific type or object class. Actually normal XML file without Namespace gets de-serialized easily but when you de-serialize XML with Namespace it gives following error

“There is an error in XML document”

Resolution is very simple actually you just need to include Namespace with XMLSerialization Class and exception will go away.


XmlSerializer serializer = new
XmlSerializer(typeof(Books), http://schemas.com/BooksSchema&#8221;);


Books books = (Books)serializer.Deserialize(new System.IO.FileStream(“XmlDeserializationSample.xml”,System.IO.FileMode.OpenOrCreate));

<?xml
version=1.0
encoding=utf-8 ?>

<ns1:Books
xmlns:ns1=http://schemas.com/BooksSchema>

<ns1:Book>

<ns1:Title>Professional.ASP.NET.MVC.2</ns1:Title>

<ns1:Author>Scott Hanselman</ns1:Author>

</ns1:Book>

</ns1:Books>