While working in BizTalk Server solutions sometimes we need to access certain properties inside pipelines, especially:
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:
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");
}
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);
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:
Happy BizTalk coding!