Logo
PREGNANCY
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Server

BizTalk 2010 Recipes : Administration and Operations - Debugging Orchestrations

5/19/2011 5:32:31 PM

1. Problem

You need to debug a BizTalk orchestration.

2. Solution

You can use BizTalk's Orchestration Debugger, which allows you to set breakpoints on any shape in an orchestration. Once an instance of an orchestration executes and encounters one of these breakpoints, it will go into a wait state in the BizTalk MessageBox, allowing a developer or administrator to manually step through the orchestration.

NOTE

A dehydrated orchestration is an orchestration that has been removed from memory and persisted to SQL Server while it waits for its next action to occur, such as receiving a document. Upon this next action, the orchestration is returned to memory in the exact state prior to dehydration, and processing continues. This ability to dehydrate/rehydrate allows BizTalk Server to better utilize server resources.

The following steps demonstrate setting how to debug an orchestration.

  1. Open the BizTalk Administration Console, and navigate to the BizTalk Group Hub page.

  2. Find an instance of a currently running orchestration that you wish to debug, or find a completed instance of an orchestration that you wish to debug future instances of. For this example, click on the Completed Instances link on the Group Hub page, which will show a list of all instances (orchestrations and otherwise) that have completed.

  3. Right-click the instance of the orchestration to debug, and select Orchestration Debugger, as shown in Figure 1. The Orchestration Debugger window will open. The full orchestration will appear with a pane on the left showing a list of tracked events, as shown in Figure 2.

    Figure 1. Accessing the Orchestration Debugger

    NOTE

    Large orchestrations can take longer to load. Occasionally, with smaller development machines and larger orchestrations, you may need to wait for a while before the Orchestration Debugger window actually opens.

    Figure 2. Orchestration Debugger window
  4. To set a breakpoint, right-click any shape, and select Set Breakpoint on Class.

  5. Step through the orchestration by clicking tracked events in the left pane.

  6. At any time, select Debug => Attach. A new pane will open and display the values of all variables at the given stage of the orchestration. This allows for a full view into the state of the process. You'll notice a number of debugging actions are available on the Debug menu.

    NOTE

    You can attach only to orchestrations that have not completed. If this is the first time that the orchestration has executed, it will likely have already completed. You may need to start a new instance before the orchestration will pause on a breakpoint that has been set.

  7. Click through the tracked events in the left pane to see which steps have executed by highlighting the corresponding orchestration shapes in the right pane. The color green indicates input to a shape, and blue indicates an exit from a shape. This will aid in determining which paths have been followed (in the case of Decide and Parallel Action shapes), how many times they may have executed (for instance, how many times a loop has executed), and which step in the process may be causing an error.

  8. If desired, step into a child orchestration by clicking the event in the Tracked Events pane, which corresponds to the Call Orchestration shape. Right-click the event, and select the option to step into the child orchestration.

  9. Once all debugging has been completed on an orchestration, make sure to clear all breakpoints. Open the Orchestration Debugger on an instance of the same orchestration (any instance will do), and select Debug => Clear All Breakpoints on Class (this can be done only when not attached to an instance).

3. How It Works

While the Orchestration Debugger can be a helpful tool, especially in cases where an orchestration is deployed in a production environment and is encountering errors, developers often need a much more rapid and controllable method for debugging. It is helpful to have logging in development and in production, and the ability to turn it on and off for any given process at any given time should be available. Several techniques enable this type of debugging.

For example, using two standard .NET lines of code will allow a view into what is happening in an orchestration without opening the Orchestration Debugger:

System.Diagnostics.EventLog.WriteEntry("Demo","Value: " + strValue);
System.Diagnostics.Trace.WriteLine("Value: " + strValue, "Demo");

The System.Diagnostic.EventLog.WriteEntry method will log entries to the Windows Event Viewer. To view this logged event, open the Control Panel, select Administrative Tools, and double-click Event Viewer. Events will be logged to the application log, and you'll need to refresh the display to see results as they are written.

NOTE

The user that runs the orchestration (whatever the host user has been configured to be) must have rights to write to the Event Viewer to use the System.Diagnostic.EventLog.WriteEntry method.

The System.Diagnostics.Trace.WriteLine method will allow all of the trace outputs to be read by attaching to the main BizTalk executable and monitoring in Visual Studio. Use the following steps to do that monitoring:

  1. In Visual Studio, select Debug => Attach to Process.

  2. In the window that opens, find BTNTSvc.exe, and highlight it. Click the Attach button.

  3. Run an instance of the orchestration. Trace information will be made available in the Output window in Visual Studio.

One way to use the System.Diagnostic methods for debugging/tracing in orchestrations is to wrap the logging code in an If statement and create a TraceFlag that can be set in a configuration file, such as the BTSNTSvc.exe.config file in the root BizTalk Program Files folder. Here is an entry you could add to the BTNTSvc.exe.config file:

<add key=" TraceFlag" value="true"/>

Listing 1 demonstrates how to retrieve the TraceFlag and, based on its value, log information.

Example 1. Configurable Trace Flag
// set the trace flag based on a value stored in the BizTalk Config File
// note that blnTraceFlag must be defined in the orchestration variables


blnTraceFlag = System.Convert.ToBoolean(System.Configuration.
ConfigurationSettings.AppSettings.Get("TraceFlag"));

// set the source to something unique for this orchestration
strSource = "DebugDemoOrchestration";

// Trace
if(blnTraceFlag == true){
strValue = System.Convert.ToString(intValue);
System.Diagnostics.EventLog.WriteEntry(strSource,"Value: " + strValue);
System.Diagnostics.Trace.WriteLine("Value: " + strValue, strSource);
}

When using this approach, keep tracing information separate in the orchestration from other functionality, and label it appropriately. You can do this by dedicating an Expression shape to a single trace event and naming it Trace (for example), as shown in Figure 3.

Figure 3. Expression shape for tracing

One of the most helpful ways to debug is to see the actual XML of a message, especially before and after mapping. This can be done by setting a variable of type System.Xml.XmlDocument equal to an orchestration message and then tracing the value of this variable, as shown in Listing 2.

Example 2. Tracing XML
// set the xmlDoc variable equal to the message to be traced.
// msgOrch is an orchestration message
xmlDoc = new System.Xml.XmlDocument();
xmlDoc = msgOrch;
System.Diagnostics.EventLog.WriteEntry(strSource,"Value: " + xmlDoc.OuterXml);
System.Diagnostics.Trace.WriteLine("Value: " + xmlDoc.OuterXml, strSource);


NOTE

The maximum size of a string that can be written to the Windows Event Viewer is 32KB. Often, XML messages will exceed this size. If a string longer than 32KB is written, an exception will be thrown, and the orchestration will terminate (unless appropriate exception handling is implemented). You can truncate the length using .NET code. There is no limitation to the size when using the Trace.WriteLine method.
Other -----------------
- Monitoring Exchange Server 2010 : Debugging Network Connectivity (part 4) - Using Exchange Server ActiveSync
- Monitoring Exchange Server 2010 : Debugging Network Connectivity (part 3)
- Monitoring Exchange Server 2010 : Debugging Network Connectivity (part 2)
- Monitoring Exchange Server 2010 : Debugging Network Connectivity (part 1) - Using Telnet to Test SMTP Communication
- Backing Up Windows Server 2008 R2 Role Services (part 3)
- Backing Up Windows Server 2008 R2 Role Services (part 2) - Backing Up Active Directory & Active Directory Recycle Bin
- Backing Up Windows Server 2008 R2 Role Services (part 1) - Backing Up the System State & Excluding Items from Backup
- Backing Up the Windows Server 2008 R2 Environment : Managing Backups Using the Command-Line Utility wbadmin.exe and PowerShell Cmdlets
- BizTalk 2010 Recipes : Administration and Operations - Managing BizTalk Applications
- BizTalk 2010 Recipes : Administration and Operations - Resubmitting Messages
- BizTalk 2010 Recipes : Administration and Operations - Troubleshooting Suspended Services
- SharePoint 2010 PerformancePoint Services : Maintaining a PPS Deployment - Migrating from PPS 2007
- SharePoint 2010 PerformancePoint Services : Maintaining a PPS Deployment - Managing PPS
- SharePoint 2010 PerformancePoint Services : Maintaining a PPS Deployment - Planning for High Availability
- Backing Up the Windows Server 2008 R2 Environment : Windows Server Backup Overview & Using Windows Server Backup
- Backing Up the Windows Server 2008 R2 Environment : Creating the Disaster Recovery Solution
- Backing Up the Windows Server 2008 R2 Environment : Understanding Your Backup and Recovery Needs and Options
- Active Directory Domain Services 2008 : Manage the Active Directory Domain Services Schema - Deactivate Classes
- Active Directory Domain Services 2008 : Manage the Active Directory Domain Services Schema - Create Classes
- Active Directory Domain Services 2008 : Configuring Attributes Not to Be Indexed for Containerized Searches & Configure Attribute Range
 
 
Most view of day
- Sharing Your Computer with Others : Create a User Account, Switch Between Accounts
- Microsoft Exchange Server 2007 : Managing a Windows Server 2003 Cluster
- Microsoft Dynamic GP 2010 : Purchase Order Processing
- Exchange Server 2007 : Migrating from Windows 2000 Server to Windows Server 2003 (part 5) - Moving Operation Master Roles
- Windows Phone 7 : The Silverlight Controls (part 5) - Interactive Controls - CheckBox Controls, RadioButton Controls
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Adding Security Encryption to a Workbook
- System Center Configuration Manager 2007 : Operating System Deployment - Site Systems
- System Center Configuration Manager 2007 : Creating SQL Reporting Services Subscriptions
- SharePoint 2010 : Configuring Search Settings and the User Interface - Web Parts (part 4)
- Reporting in Dynamics AX 2009 : Reporting Overview
Top 10
- Windows Phone 8 : Configuring Mailbox Settings (part 5) - Configuring Automatic Replies
- Windows Phone 8 : Configuring Mailbox Settings (part 4) - Lightening the Display,Changing the Mailbox Sync Settings
- Windows Phone 8 : Configuring Mailbox Settings (part 3) - Message Signatures, Blind CCing Yourself
- Windows Phone 8 : Configuring Mailbox Settings (part 2) - Unlinking Mailboxes, Conversation View
- Windows Phone 8 : Configuring Mailbox Settings (part 1) - Linking Mailboxes
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 6) - Tracking installed roles, role services, and features
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 5) - Installing components at the prompt
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 4) - Managing server binaries
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 3) - Adding server roles and features
- Managing Windows Server 2012 Systems : Configuring Roles, Role Services, and Features (part 2) - Installing components with Server Manager - Viewing configured roles and role services
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro