Pages

How To Expose / Promote the BTS ReceiveLocationName Property in Message Context Of a Biztalk Message

Wednesday, September 14, 2011
Post by Evan Aussenberg

There are some BizTalk properties that are not exposed in any property schemas from BTS 2006 R2. If your development project is such that you can add a new property schema or add a new BizTalk project then it is possible to access these properties from an orchestration. Because they are context properties they are not available for routing. 

One such property is the ReceiveLocationName property. While the ReceivePortName property is available in the BTS namespace the ReceiveLocationName property is not. Therefore, this syntax from an example orchestration expression shape results in a compile time error:  strReceiveLocation = myMsg(BTS.ReceiveLocationName); 
ReceiveLocationName Property 

We can easily see the ReceiveLocationName property in messages that come into BizTalk. The question is how to get its value into an orchestration? 

  

Code Example 

As you probably know, property values are identified by the property target namespace and property name. We won't ultimately use the following code, but for demonstration purposes in a custom pipeline component we can assess a property value by coding something like this: 

// Namespace of the property // string sysNamespace =      "http://schemas.microsoft.com/BizTalk/2003/system-properties"; 
  
// Or instead of hard coding the namespace: // Assuming the property namespace for ReceivePortName is the same // for ReceiveLocationName: // BTS.ReceivePortName BTSPropReceivePortName = new BTS.ReceivePortName(); sysNamespace = BTSPropReceivePortName.Name.Namespace;    // Assign the receive location name // string receiveLocationName =      pInMsg.Context.Read("ReceiveLocationName", sysNamespace); 
You can see from the last line of code from above, that to retrieve a message property requires nothing more than knowing the property name and the property target namespace. 
Adding a Property Schema 

As far as BTS message properties go, they can be assigned Property Schema Base types of MessageDataPropertyBase (default) orMessageContextPropertyBase. MessageDataPropertyBase means that the XPath to the property value in the message must exist. A MessageContextPropertyBase property means that the XPath may or may not exist. 
Taking this information into account we can expose the RecieveLocationName using the following steps. Note steps 1 – 4 are just suggestions.
1. Create a property schema, and perhaps create a new BizTalk project.
2. Add a new property schema. Let’s call it “schBTSExtra.xsd”.
3. Change the namespace of the .NET schema type to “BTSExtra”. This is just a shortened namespace similar to the “BTS” namespace in the Microsoft.BizTalk.GlobalPropertySchemas assembly.
4. Open the new schema if it is not already opened.
5. Change the name of Property1 (it was added by default when creating the new property schema) to ReceiveLocationName.
6. Set the Property Schema Base to MessageContextPropertyBase.
7. Highlight the “Schema” node and change the schema’s Target Namespace to 
http://schemas.microsoft.com/BizTalk/2003/system-properties
8. Compile the project.
Property Schema Example 
That’s all there is to it… now in your orchestration after referencing the new schema project (or you added this schema directly to your orchestration project) you can use an expression such as:
// Trace output from an orchestration expression shape // traceMsg = purchaseOrder(BTSExtra.ReceiveLocationName); if (traceMsg == null) {     traceMsg = "<null>"; } System.Diagnostics.Trace.WriteLine("Receive Location Name: " + traceMsg);
Here is the result when testing my own orchestration: 

 

External Links from MSDN

No comments:

Post a Comment

Post Your Comment...