Biztalk BAM Blogging Introduction

As 2005 is coming to a close, I want to take this opportunity to wish you a happy 2006; this also means we are inching closer towards the release of BizTalk 2006 🙂

What is this blog good for…you may ask?  This blog is for you the users.  🙂  The topic that it focuses on is BizTalk in general and BizTalk BAM specifically.  I will use this as a central depository (referenced from my forum replies) as well as direct replies from which to disseminate insights and personal experience from working with this product on a daily basis. 

You, as the user can help me better help you.  Please use the comment (on this posting) to ask for anything you may want me to delve into… of course, this got to be BizTalk and BAM related 🙂


Happy BAMifying,

Keith Lim


Comments (22)

  1. Eric Stott says:

    Is there an example using BAM components only, to put a time of transaction. I would like to log file name, sender, etc. But what I would also like to see is the time that it happened. Is there a way to set this up in Excel and then deploy it using the BM.exe? Also, if this example could be done in 2k4, that would also be helpful.

  2. keithlim says:

    When you say using BAM components only, are you refering to using BAM but without the BizTalk pipelines and orchestrations? If this is what you want to do, you can simply create a BAM definition that includes a milestone such as FileReceived. You would then need to use DirectEventStream (for synchronous calls) or BufferedEventStream (for asynchronous calls) and point it to a licensed BizTalk server. You can do this by copying only the required DLL’s over to the desired box. (You don’t need to have BizTalk license for this box in order to use it.)

    However, if you want to capture information of files/mesages as they pass thru Biztalk pipelines and orhchestration: these are the options you have in Biztalk 2004:

    1) For messaging only scenerio (pipelines only and no orchestration also known as CBR), you will need to write custom pipeline components and embedded the usage of DirectEventStream or BufferedEventStream calls, you can then capture the desired file information. You can also write your own adaptor with the same kind of embedded code.

    2) For scenario with orchestration, you can embed code into the orchestration or using TPE. Note that, capturing the info at orchestration level may not be the right place since, message may get suspended in pipelines and will never get processed by orchestration.

    I will create some downloadable samples soon…

  3. Eric Stott says:

    This sounds interesting, I know how to do this in an orchestration, and have a simple one available. but what would be really interesting to see is a flat file parser with a decode component before it that simply writes information to the BAM database. I would be interested in seeing something done in the pipeline.

  4. Eric Stott says:

    Second Request:

    In your title, you have OrestrationEventStream. I saw the fix report on it, but I am trying to invoke it and by using a variable using the .NET class Microsoft.BizTalk.Bam.EventObservation.EventStream, I am not able to invode it. Am I missing the latest pack, and I need to call MS Support for it (I already have SP1 2k4)? What also would be great would be to have an example that SHOWS why using this is better than either Buffered or Direct Event Stream, as I see the difference in Direct and Buffered, but don’t see any ‘usefullness’ in this.



  5. keithlim says:

    To answer your first question on how to write BAM code from pipeline. Adapt the SDK CustomComponent (found in …/SDK/Samples/Pipelines/CustomComponent) sample, you will find two directories:

    1) FixMsg – the custom pipeline component (you will need to splice BAM code here)

    2) PipelineComponentSample – custom pipeline and will use the above custom pipeline component.

    Modify the FixMsg to include the below sample (Search for Execute method):

    public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)


    IBaseMessagePart bodyPart = inmsg.BodyPart;

    if (bodyPart!=null)


    //Splice BAM Code here:

    WriteBAMEvent(pc, "Execute", inmsg);


    return inmsg;


    // Add a new method to write to BAM

    private void WriteBAMEvent(IPipelineContext context, string StageDescription, IBaseMessage inmsg)


    EventStream _BAMEventStr = null;

    // Create an EventStream instance



    // Use can use BES/DES or MES

    // DES – DirectEventStream – writes direct to BAMPrimaryImport (Synchronous call, no latency)

    //_BAMEventStr = new DirectEventStream("Integrated Security=SSPI;Data Source=.;Initial Catalog=BAMPrimaryImport",1);

    // BES – BufferedEventStream – writes to MessageBox (Asynchronous call, no wait in call)

    // _BAMEventStr = new BufferedEventStream("Integrated Security=SSPI;Data Source=.;Initial Catalog=BizTalkMsgBoxDb",1);

    // MES – MessagingEventStream – Async and participates in Pipeline transaction context).

    // – Note: Available in BizTalk 2004 with SP1 patch

    _BAMEventStr = context.GetEventStream();


    catch(Exception e)


    throw (e);


    // Sample BAM Event Code here:

    string ActivityID;

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

    ActivityID="BAM_" + Guid.NewGuid().ToString() + "_" + DateTime.Now + "_" + StageDescription;

    //Start the activity record identified by ActivityID


    _BAMEventStr.UpdateActivity("PurchaseOrder",ActivityID, "ProductName","QFE1117");


    // Optional Flush



    To understand the above and details on how to fetch message specific data, please refer to sectio on Developing Pipeline Components in the help or use this link:

    You would at least need to implement these interfaces.

    IBaseComponent, IComponent, IComponentUI.

    The above is tedios and is the only means for writing to BAM in Biztalk 2004. In Biztalk 2006, you can do some of this easily via TPE drag and drop.



  6. Eric Stott says:

    This pipeline component change looks interesting, but for the "Data Source=.;" – I have been using the Business Rules Engine to modify the actual server that this database resides on, as the SQL Server is never on the same box as the BizTalk application. Does the ‘.’ ‘magically’ determine where the BizTalk SQL Server resides on so I can take the call to the BRE out, or will I have to put in a call to the BRE in the pipeline also? As far as a promotion process, if this does not resolve the home db server, is there a registry key, or some other way to have the BAM code automatically determine where the MessageBoxDb or BAMPrimaryImport database is?

  7. keithlim says:

    No the . resolves to the localhost machine. The usage of MessagingEventStream, a new feature available in BizTalk 2004 SP1 onwards, will take care of this for you, see sample code (in my previous comment) of the below line:

    _BAMEventStr = context.GetEventStream();

    Pros for this is that the eventstream transaction within the context of the pipeline, meaning, if something goes wrong with the pipeline, the event stream is not written as well, if it suspended, the eventstream is suspended as well. If you use DES or BES, their transactions are independent of the pipeline processing.

  8. keithlim says:

    Availability of OES (OrchestrationEventStream)

    This is only available in Biztalk 2006. This allows the EventStream to be transaction within the context of Orchestration, meaning, when the Orchestration persists, EventStream will persist as well. You do not need to write EventStream from an atomic scope (huge penalty in performance) to ensure transaction consistency.

  9. Eric Stott says:

    so _BAMEventStr = context.GetEventStream(); will get the home database, so I don’t need to define it for every enviornment?

  10. keithlim says:

    That’s right, _BAMEventStr = context.GetEventStream(); will return a EventStream instance (of MessagingEventStream) with the knowledge of where the MessageBox database.

  11. Eric Stott says:

    "Availability of OES (OrchestrationEventStream)

    This is only available in Biztalk 2006."

    Is this not part of SP1, and something that needs to have a call into support to get?

  12. Eric Stott says:


    I could find no documentation on this, can you provide a link on the MSDN site that expains this?

  13. keithlim says:

    Availability of OES (OrchestrationEventStream)

    This is only available in Biztalk 2006, there is no patch for this for Biztalk 2004 SP1. It is also planned for BizTalk 2004 SP2.

    And there is no documentation out there yet, we are still working on it.

  14. keithlim says:


    There is no documentation on this either, we are working on it as well. However, if you have Biztalk 2006 pre release version installed, you will find the SDK BAM End To End sample containing this.

  15. Eric Stott says:

    Availability of OES (OrchestrationEventStream)

    This is only available in Biztalk 2006, there is no patch for this for Biztalk 2004 SP1. It is also planned for BizTalk 2004 SP2.

    And there is no documentation out there yet, we are still working on it.

    so is wrong when it states that it is available for BTS 2k4, and is there any timelines when SP2 will be released, as I see a big use for this feature in some of our current processes?

  16. keithlim says:

    Availability of OES (OrchestrationEventStream)

    Thanks for pointing that out. However, I generally don’t recommend users to apply hotfixes unless it is absolutely needed 🙂 When the hotfixes are rolled into a service pack, they are much more well tested and robust. See Hotfix information section in the link:

    Hotfix information

    A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next BizTalk Server 2004 service pack that contains this hotfix.

  17. Eric Stott says:

    Another BAM related question:

    Is there an example (step by step) of how to include the deployment AND re-deployment of a BAM solution in an MSI package. I know that there is a BTTdeploy.exe. It would be perfect if there was an example of how to automate both the deployment of BAM and the deploy of the .btt file in an MSI package. If there is an automated way to do a re-deployment of BAM, archive of the current BAM activities, undeploy of the BAM view, deploy the .xml and then associate the .btt file, that would be great.


    Eric Stott

  18. ericstott says:

    Is there a way to retrieve data from the BAMPrimaryImport database using the Microsoft.BizTalk.Bam.EventObservation?



  19. keithlim says:

    I have made a new entry on retrieving data from BAMPrimaryImport:

  20. ericstott says:

    I am pulling data from a XML ts:time field and sending it to a BAM activitiy that is defined as DATETIME, however when the insert happens, the time that is in the XML document is <Transaction_Set_Time>09:53:27</Transaction_Set_Time>, however in the database it ends up as 2006-12-04 15:54:25.000, is this because of the Time Zone set to GMT? What would be the easiest way to adjust to the correct time zone in the eventStream.UpdateActivity call?



  21. Thirumurugan says:

    How to include BAM deployment and TPE application on the MSI package.



  22. Thirumurugan says:

    Hi Keith,

    How to include BAM deployment and TPE applilcation on the MSI package.  Or is there any way to automate this process.