BizTalk Trick: Display Debug Messages in an Orchestration (MessageBox)

I agree: the Health and Activity Tracker tool of BizTalk 2004 is the source of information if something goes wrong in BizTalk. But sometimes (for example during development) it's quite a hassle to fire up the Health and Activity Tracker, find your message and navigate to the Orchestration Debugger, especially since this tool is not (yet?) integrated in Visual Studio.NET.

So what does a developer typically do if he/she needs to get some debug information from a Windows.Forms application while the application is running? Will he/she set a breakpoint, fire up the application and enter an expression in the Command Window? Maybe... Probably he/she will quickly add a MessageBox.Show(something) in the code and fire up the application, right? It would be nice if we could do the same in a BizTalk Orchestration! But there is one small problem: the BizTalk processes aren't running with the identity of the currently logged on user; so the MessageBox won't be visible for that interactive user by default. Luckily you can change this behaviour by using MessageBoxOptions.ServiceNotifcation option when invoking the MessageBox.Show method. From the MSDN Library:
ServiceNotification: The message box is displayed on the active desktop. The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.

I'm using following class which I've put in a class library that's deployed in the GAC, so the class can be called very easy from an Expression shape in an Orchestration once you've added a reference to the assembly. The expression could be something like this (you don't need an instance of the MessageBox class, the Show method is declared static):
Ordina.BizTalk.Debug.MessageBox.Show("OK!");

Here's the complete code. Oh, by the way, please do not forget these expressions when you put your project in a production environment! :-)

using System;
using System.Windows.Forms;

namespace Ordina.BizTalk.Debug
{
 /// <summary>
 /// Helper class to display debug information in BizTalk orchestrations.
 /// </summary>
 public class MessageBox
 {
  private MessageBox()
  { /* Can not create instance! */ }

  static public void Show(string text, string title,
   MessageBoxButtons buttons, MessageBoxIcon icon,
   MessageBoxDefaultButton defaultButton)
  {
   System.Windows.Forms.MessageBox.Show(
      text,
      title,
      buttons,
      icon,
      defaultButton,
      MessageBoxOptions.ServiceNotification);
  }

  static void Show(string text, string title)
  {
   Show(
    text,
    title,
    MessageBoxButtons.OK,
    MessageBoxIcon.Information,
    MessageBoxDefaultButton.Button1);
  }

  static public void Show(string text)
  {
   Show(text, "Ordina.BizTalk.Debug Information");
  }
 }
}

8 Comments

  • During development I often use System.Diagnostics.Trace.WriteLine in expressions and SysInternals debugview to see what's happening. Works fine !

  • Just to make sure: you're looking on the server desktop, right? If you're using Terminal Services it's possible that the messagebox shows up on monitor connected to the server.

  • You can also use DebugView from SysInternals to view the output from System.Diagnostics.Debug.Write(&quot;...&quot;)

  • Hi Jan,

    Do you have a downloadable copy of the solution project for your Ordina.BizTalk.Debug.Messagebox example?

    Otherwise if i want to try to do something like this I'm just creating a regular .net class library right?

    Thanks,
    Tom

  • sorry I mean't to say .net control library not class library...

  • Okay I got it now - it's a regular .net class library but I forgot to add in a reference to System.Windows.Forms since by default .net class projects don't expect a GUI..

  • i am very new to biztalk... I was able to compile the class into an assembly then add it as a reference to my biztalk orchestration and then I also saw the 'intellisense' within the biztalk orchestration pick it up -- so I know the reference is okay... but when i ran my orchestration nothing really happened -- but i did have a lot of windows open and also multiple desktops (windows xp power toys)... could it be a permission related?

  • It's okay it actually turns out to work fine! The reason why I didn't see anything happen initially was that I had a bunch of breakpoints on my Orchestration so it wasn't until I stepped through it in the HAT debugger that I could see the MessageBox work!

    This was a great example and nice demo that could also lead to more nice additions to Biztalk.

    When we are adding this class to biztalk as a reference is it then considered an 'Artifact' or is it just a reference class still?

    Thanks,
    Tom

Comments have been disabled for this content.