BizTalk Port name

How to access BizTalk Port names in pipelines

Published on : May 13, 2022

Category : BizTalk Server

Sandro

Author

While working in BizTalk Server solutions sometimes we need to access certain properties inside pipelines, especially:

  • For routing messages, in these cases, we are normally speaking about receiving properties like Receive Port or Receive Location names – if we focus on the topic of this post.
  • Or for logging, in this case, having the Send Port name can be useful.

To address some of these scenarios and to follow up on one of my latest BizTalk whitepapers, check: Your Guide to BizTalk Message Context Properties, and one of my latest blog posts: How to promote the BizTalk Server Receive Location Name property. We are going to explain how to access the following context properties inside a pipeline:

  • Receive Port name
  • Receive Location name
  • Send Port name

Accessing the Receive Port name inside a receive pipeline

In this sample, we will extract the name of the Receive Port that executes a receive pipeline. In your receive pipeline component, you need to implement the Execute method with the following line of code:

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
string receivePortName =(string)pInMsg.Context.Read("ReceivePortName", "http://schemas.microsoft.com/BizTalk/2003/system-properties");
}

Accessing the Receive Location name inside a receive pipeline

To actually access and promote the properties to the context of the message, we need to create a pipeline component to do the trick. In your receive pipeline component, implement the Execute method with the following line of code:

string rlocationname = (string)pInMsg.Context.Read("ReceiveLocationName", "http://schemas.microsoft.com/BizTalk/2003/system-properties");
pInMsg.Context.Promote("ReceiveLocationName", "https://BizTalk.Pipeline.Components.RcvLocationPromotion.PropertySchema", rlocationname);

Accessing the Send Port name inside a send pipeline

In this sample, we will extract the name of the Send Port name that executes the send pipeline. In your send pipeline component, implement the Execute method with the following line of code:

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
string sendPortName =(string)pInMsg.Context.Read("SPName", "http://schemas.microsoft.com/BizTalk/2003/system-properties");
}

If a send port is bound to a send port group, we could always access the Send Port Group name, but that would require doing some queries to the database since by default there isn’t any context property that will tell that information. So the solution for that is to check if that port is associated with any Send Port Group by using WMI or a SQL Server Query.

Of course, you can follow the same strategy to access other properties like:

  • Filename: string fName =(string)pInMsg.Context.Read(“FileName”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”);
  • Message type we are processing: string msgType =(string)pInMsg.Context.Read(“MessageType”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”);
  • Operation we are setup for the send port: string operation =(string)pInMsg.Context.Read(“Operation”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”);

Happy BizTalk coding!