BizTalk and WMI

This will be a rather short blog post because I intend to write a much longer blog post about a this topic once I finishing coding a side project that uses WMI with BizTalk. So for now I am just going to throw down some quick, dirty code and explanation to show the power and usefulness of this topic.

If your a BizTalk guy, you probably get tired of opening the HAT and saving messages then terminating. Unless of course your BizTalk solution is just perfect and this never happens to you...ya ok.

What I am going to do is show you quick example of how to generate Managed WMI classes for BizTalk and show an example of how useful it can be.

First thing is to download this:
Management (WMI) Extensions for Visual Studio .NET 2003 Server Explorer

Next thing is connect to the BizTalk box with Server explorer in Visual Studio. Right click on the "Management Classes" and click "Add Classes"

Now Select "ROOT\MicrosoftBizTalkServer" and click "ADD>"

Now you see all the classes you can deal with in your Server Explorer.
Right click on "MSBTS_ServiceInstance" and select "Generate Managed Class"
Now you have a class file in your solution that you can program with.

Pretty cool eh?
Go ahead and generate one more class from "MSBTS_MessageInstance"

So, lets writes some quick dirty code to do something. I am sure I have at least 100 suspended messages on my local BizTalk server box to work with here :).

   11  ROOT.MICROSOFTBIZTALKSERVER.ServiceInstance.ServiceInstanceCollection _colServiceIns;
   13   //get a collection a ServiceInstance that are in "Suspended Not Resumable" status
   14   _colServiceIns= ROOT.MICROSOFTBIZTALKSERVER.ServiceInstance.GetInstances
(String.Format("ServiceStatus='{0}'", 32));
   16   //Loop though them
   17   foreach(ROOT.MICROSOFTBIZTALKSERVER.ServiceInstance _serviceIns in _colServiceIns)
   18   {
   20       Console.WriteLine("ServiceInstance GUID: "+ _serviceIns.InstanceID + "\n");
   21       Console.WriteLine("Error: " + _serviceIns.ErrorDescription);
   23       ROOT.MICROSOFTBIZTALKSERVER.MessageInstance.MessageInstanceCollection _messCol;
   25      //get a Collection of messageInstance with a condition that the ServiceInstanceID 
   26      //of ServiceInstance is equal to ServiceInstanceID of MessageInstance
   27      _messCol= ROOT.MICROSOFTBIZTALKSERVER.MessageInstance.GetInstances
(String.Format("ServiceInstanceID='{0}'", _serviceIns.InstanceID ));
   29      //Loop though the MessageInstance collection and save off the message
   30      foreach(ROOT.MICROSOFTBIZTALKSERVER.MessageInstance _messIns in _messCol)
   31      {
   32          Console.WriteLine("Saving to File");
   33          _messIns.SaveToFile(@"C:\here\");
   34          Console.WriteLine("Done Saving");
   35      }
   36   }

All that happens here is, we get a collection of ServiceInstance that are "Suspended Not Resumable", loops through some of the properties and displays them. Then, matches up the MessageInstance with its ServiceInstance and saves off the message to a location on disk and Terminate.

Here is our output.


Ed K.

Posted in

Friday, 26 January 2007 20:14:07 (Pacific Standard Time, UTC-08:00)
What about VB sample code? Huh?
Saturday, 27 January 2007 22:07:51 (Pacific Standard Time, UTC-08:00)
Just take off my semi's and put Dim everywhere, then change my "real code" into an english paper. :)
Monday, 17 September 2012 10:40:48 (Pacific Daylight Time, UTC-07:00)
Thanks for sharing the script.
I'm using BizTalk Server 2010. Is there a way to get all suspended instances (4 or 32) by Application?

(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview