BAM Continuation (Custom Code)

Hello,

I have custom pipeline that I'm using to write BAM events. I'm using the MessagingEvent stream to enable continuation such as:

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

//Start the activity record identified by ActivityID
_BAMEventStr.BeginActivity("PurchaseOrder",ActivityID);

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

_BAMEventStr.EndActivity("PurchaseOrder",ActivityID);

I also have an orchestration that includes a custom .net component for writing BAM activites. I'm utilizing serializable classes and strongly typed APIs (GenerateTypedBAMAPI tool) to write to the BAM db.My question centers around how to access the unique activityid in my .net code, which was initially created in the pipeline. I presume that I have to pass this data to the orchestration. I would really like to see an example of how this is done.

Thanks.

[1502 byte] By [hj1] at [2008-2-18]
# 1

Hi hj1,

This is a good question; not hard, just good Smile

You have many options here. Logically, you need a way of storing this ActivityID along with the process, from when its created inside the pipeline, to when its continued inside an Orchestration.

One way to keep track of this ActivityID is to push the id to the header section of the Message aka the MessageContext. To push it here you will need to "Promote" the value, however Promotion does come at a cost, you're adding overhead to the message process for purposes of BAM Tracking. If you can live this then this option may work for you.

You can promote the value two ways, you can use Property Field promotion, or distinguished field promotion. Property Field promotion dictates that you need a specia "property"l schema deployed that contains a element and element type of the data (string - ActivityID) that you are promoting eventually inside the pipeline. Distinguished field promotion is just when you add a value to the MessageContext.

Code Snippet

Code:

//For writing a distinguished field value

iinMsg.Context.Write( "/*[local-name()='MyBamInfo' and namespace-uri()='http://mycompany.com']/*[local-name()='ActivityID' and namespace-uri()='']", http://schemas.microsoft.com/BizTalk/2003/btsDistinguishedFields", ActivityID);

//Create and deploy a custom property schema, and add an element and derive it from the MessageContextPropertyBase (if not in message payload, otherwise MessageDataPropertyBase if it will be in the message: this is set underneath the Propery Base Schema property)

//For writing a property field value

inMsg.Context.Promote( "propertySchem.ActivityID", "http://schemas.microsoft.com/BizTalk/2003/system-properties", ActivityID);

In anycase, you can use these values inside the Orchestration instance for your BAM purposes. Depending on if you use Property Field or Distinguished Field, the way you access the values you promoted are going to be different. For Distinguished fields, you'll have to use code within the orchestration to get the distinguished field values.

Whereas, Property promoted values can be used with the Message(PropertySchema.ActivityID) syntax for the value that you promoted.

Another option is to add this ActivityID to your message schema and populate the ID within the message (inside the pipeline if you'd like) and promote the values using either Distinguished or Property field. Then you can access the values using the normal msg.ActivityID, or Msg(PropertySchema.ActivityID) options

Note: if you're using continuation you don't want to call EndActivity within the pipeline component, because that will mark the activity instance record as "IsComplete" which commits the tracking record.

Here is a link for more help:

http://blogs.msdn.com/keithlim/archive/2006/02/08/527227.aspx

(It's kind of old but it's stll good.)

HTH

DwightGoins at 2007-10-2 > top of Msdn Tech,BizTalk Server,BizTalk Interceptors...