BAM in Orchestration

In BizTalk, BAM  applies on pipeline level and in orchestration. Here we are going to implement BAM in Orchestration through BAM API programming.

For more details of BAM APIs, you can refer to

Normally for BAM Programming below three functions are required under EventStream class.

  • BizTalk.Bam.EventObservation.OrchestrationEventStream.BeginActivity
  • BizTalk.Bam.EventObservation.OrchestrationEventStream.UpdateActivity
  • BizTalk.Bam.EventObservation.OrchestrationEventStream.EndActivity

If you want some more advance feature in BAM tracking then you can refer below reference:


Add below Dlls in BizTalk project references:

  • Biztalk.BAM.Xlangs.dll
  • BizTalk.Bam.EventObservation.dll

Write below code in orchestration expression shapes:

//Create a new, unique activity identifier to use as the ActivityID in BAM

string activityId = Guid.NewGuid().ToString();

Microsoft.BizTalk.Bam.EventObservation.OrchestrationEventStream.BeginActivity(ActivityName, activityID);

// Updates the activity record.

Microsoft.BizTalk.Bam.EventObservation.OrchestrationEventStream.UpdateActivity ActivityName, activityID, “FIleName”, msg(BTS.FileName), “ProcessStart”, DateTime.UtcNow,);

// End the activity record.

Microsoft.BizTalk.Bam.EventObservation.OrchestrationEventStream.EndActivity(ActivityName, activityID);

Here you can use different expression shape for above methods, Be sure EndActivity method should be in last of orchestration. And StartActivity methad in starting of Orchestration.

Below is explanation of data and function which are used in orchestration expression shapes:

ActivityName: BAM Definition File Name

ActivityID: It can be a GUID or any unique id

UpdateActivity function:

public virtual void UpdateActivity( string activityName, string ctivityInstance,                     params object[] data)

In Update activity, after first two parameters, data items are next parameters which are defined in key value pairs.

These data items can be defined in single UpdateActivity function as well as in separate activity function. E.g. In below BAM table, there are following data items.

Data1, data2, starttime, endtime, errordetails, status, lastmodified.

Here we can write update function as per requirements, it’s not mandatory to define all data items in one time.

UpdateActivity(“BAMSample”, ActivityID, “starttime”, DateTime.Now);

UpdateActivity(“BAMSample”, ActivityID, “Status”, “OperationStart”);


You can track info on BAM Portal or BAM definition table in BAM Primary Import Database.

When you defining BAM Definition file then BAM creates five table in BAMPrimaryImport table.

You can check data in Bam_<BAM Definition File>_Completed table.

e.g. bam_BAMSample_Completed

How does EventStream work in Orchestration?

The OES API stores tracking data first in the BizTalk MessageBox database. Periodically the data is processed and persisted to the BAM Primary Import database by the Tracking Data Decode Service (TDDS).

The OES API is found in the Microsoft.BizTalk.Bam.EventObservation namespace.



In BizTalk, BAM (Business Activity Monitoring) can be applied on pipeline and in orchestration. BizTalk also provide Tracking Profile Editor tool to implement BAM in BizTalk,  You can get info about tacking profile editor from below reference:

But this tracking tool has some limitation (for more info you can refer to ),  that’s why we need to move to apply BAM through programming. Here we are going to implement BAM in BizTalk through programming. Before going to coding we need to understand concept of BAM API, which is used in BAM Programming.

The BAM API defines four main classes:

  • DirectEventStream (Synchronous, no latency): used in a .NET application to do a buffered write of data to BAM. Here data is persisted synchronously to the BAM Primary Import database. Except for DES, all other EventStream classes are asynchronous and have some latency. The data is first persisted to MessageBox and subsequently processed by TDDS which moves data into the BAMPrimaryImport database.
  • BufferedEventStream (Asynchronous, high throughput, some latency): used in a .NET application to do an unbuffered write of data to BAM.
  • OrchestrationEventStream (Asynchronous, participates in BizTalk orchestration transactions): used within an orchestration; Provides transactional consistency with the orchestration.
  • MessagingEventStream (Asynchronous, participates in BizTalk Server pipeline transactions): used within a pipeline; Provides transactional consistency with the messaging engine.

All of these classes are derived from the base class EventStream.


For BizTalk OrchestrationEventStream (For Orchestrations) and MessagingEventStream (For Pipelines) are applicable and other two event streams are applicable for non-Biztalk e.g. WCF and WF. Link is below for how to apply BAM through BAM API in BizTalk Pipeline and Orchestration.

Apply BAM in Pipeline:

Apply BAM in Orchestration:

The EventStream APIs for BAM reside in the Microsoft.BizTalk.BAM.EventObservation namespace. To code against the APIs, you must add the following DLLs to your project reference and include the namespace in your code with the following using statement:

using Microsoft.BizTalk.Bam.EventObservation;

  • BizTalk.BAM.EventObservation.dll (Available at C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\Tracking)
  • Biztalk.BAM.Xlangs.dll (Available at C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\Tracking): This DLL is required when coding for Orchestration event streams.
  • BizTalk.Pipeline.dll (Available at C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2): This DLL required when using coding pipeline contexts for Messaging event streams.