Tuesday, March 09, 2004 1:21 PM Jan Tielens

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");
  }
 }
}

Filed under:

Comments

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

Sunday, May 16, 2004 6:44 AM by Steef

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

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

Wednesday, May 19, 2004 4:08 PM by PM

I tried to use this class in the orchestration, but the messagebox is not displayed on the desktop? Do I have to do anything else?

Thanks

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

Monday, May 24, 2004 3:06 PM by Jan

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.

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

Thursday, August 05, 2004 5:53 PM by Phil

You can also use DebugView from SysInternals to view the output from System.Diagnostics.Debug.Write("...")

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

Thursday, March 01, 2007 5:45 PM by Tom

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

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

Thursday, March 01, 2007 6:10 PM by tsinqu2005

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

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

Thursday, March 01, 2007 6:19 PM by tsinqu2005

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..

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

Thursday, March 01, 2007 7:01 PM by tsinqu2005

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?

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

Friday, March 02, 2007 9:20 AM by tsinqu2005

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