Introduction to Functoids

Introduction to Functoids

I am sure you have heard about functions, but what about functoids? Functoids or BizTalk functoids are, in a way, small reusable functions that you build just like functions. These are like operations that you need to perform specific tasks on data. BizTalk comes with a good collection of readymade functoids. But you will frequently face situations where you desire a simple functionality. Let us say, you want to validate a credit card number, it will be great if we can build a functoid which can take in a credit card number and credit card type, and return true or false. This will be a very good scenario for writing a functoid of your own.

Scenario

As a learning exercise, I suggest building a functoid which calculates the perimeter of a rectangle for a fencing company. The logic of the functoid implementation is really concise:

2   x (length + breadth)

A Bird's Eye View of the Steps

To create a BizTalk functoid, we need to briefly do the following:

  • Derive our functoid from Microsoft.BizTalk.BaseFunctoids.
  • Give it all resource strings like function name, function bitmaps to be displayed in the mapper, tool tip text, and description.
  • Give it a unique GUID and a functoid ID.
  • Specify what category the functoid belongs to (Math, Logical, String etc..).
  • Specify input and output parameters.
  • Specify the input and output connection types.
  • Specify the function to call.

Getting Down to Business ..

I have broken down the activity into a series of logical steps.

Step 1: Creating your functoid project

You need to create a functoid as a class library. So we need to select a class library project to begin. Make sure you give a proper namespace name for it as we will need this to load the functoid later, using Reflection. We will use Custom.Biztalk.MathFunctoid as the namespase in our example:

sample screenshot

Step 2: Signing the DLL with a key

You need to have a strong name for this assembly to get it loaded into the toolbox. So create a strong name and sign it:

C:\Samples\MathFunctoid > sn   -k mathFunctoid.snk

Once you have the strong key generated, insert the line below to the AssemblyInfo.cs:

[assembly: AssemblyKeyFile("..\\..\\mathFunctoid.snk")]

Step 3: Give a unique ID for this assembly

We need to give a unique ID for this assembly. Using GUIDGEN from the Visual Studio prompt, generate a new GUID and add the following to the AssemblyInfo.cs:

[assembly: Guid("5DE500CC-45BC-454b-A23D-24449899042C")]

Step 4: Add the class skeleton

We need to have a class to implement this functionality, so add a class and call it CPerimeter (or any meaningful name of your choice):

screenshot

Once the class is added, add the following lines in the namespace inclusion section at the top of your class file:

using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;
using System.Globalization;
using System.Resources;

Step 6: Add references to BizTalk base functoids

In the project references, add a reference to Microsoft.BizTalk.BaseFunctoids.dll. This DLL implements all the base classes we need to create a functoid.

Step 7: Add a resource file

In Visual Studio, go to File->Add New Item->Resource File.

screenshot

I named the resource file Mathresource.resx for this example. Now, add the following resource strings and specify their custom descriptions:

Resource ID Value Explanation
IDS_CONVERTINTFUNCTOID_ID 6123 A value greater than 6000
IDS_FUNCTOID_NAME “Perimeter” The functoid description in toolbox
IDS_MATHFUNCTOID_TOOLTIP “Calculates the perimeter of a rectangle” What appears on the tool tip
IDS_MATH_DESCRIPTION “Calculates the perimeter” Description of functoid in VS
IDS_PERIMETERFUNCTOID_EXCEPTION "Perimeter functoid threw an exception" Description of exception to the Biztalk subsystem

Now, create a 16 x 16 bitmap and add that to the resource file, and reference it as IDS_MATH_BITMAP using the Resource Editor.

Step 8: Implement the class

To implement this class, we derive our class from BaseFunctoid. And in the class, we load the resource file, and set the different parameters like functoid name, tool tip text, and parameters for the functoid.

public class CPerimeter : BaseFunctoid
{
static ResourceManager resmgr = new
ResourceManager("Custom.Biztalk.MathFunctoid" +
".MathResource", Assembly.GetExecutingAssembly());
public CPerimeter():base()
{
int functoidID;
functoidID = System.Convert.ToInt32(
resmgr.GetString("IDS_CONVERTINTFUNCTOID_ID"));
this.ID = functoidID;
// This has to be a number greater than 6000
SetupResourceAssembly("Custom.Biztalk.MathFunctoid" +
".MathResource", Assembly.GetExecutingAssembly());
//Set Resource strings , bitmaps
SetName("IDS_FUNCTOID_NAME");
SetTooltip("IDS_MATHFUNCTOID_TOOLTIP");
SetDescription("IDS_MATH_DESCRIPTION");
SetBitmap("IDS_MATH_BITMAP");
// Minimum and maximum parameters
// that the  functoid accepts 
this.SetMinParams(2);
this.SetMaxParams(2);
/// Function name that needs to be
/// called when this Functoid is invoked.
/// Put this in GAC                    
SetExternalFunctionName(GetType().Assembly.FullName,
"Custom.Biztalk.MathFunctoid.CPerimeter",
"CalcPerimeter");
//Category for this functoid.
this.Category = FunctoidCategory.Math;
//Input and output Connection type
this.OutputConnectionType =
ConnectionType.AllExceptRecord ;
AddInputConnectionType(ConnectionType.AllExceptRecord);
}
}

Step 9: Implement the function logic

Now, we implement the functoid logic for the function name specified in the above step, using SetExternalFunctionName. The code below trims the incoming values. This is done because in XML, string data that are numerals could contain white spaces.

public string CalcPerimeter(string RectangleLength,
string RectangleBreadth)
{
int ilength = 0;
int ibreadth = 0;
int iPerimeter = 0;
ResourceManager resmgr = new ResourceManager("Custom." +
"Biztalk.MathFunctoid.MathResource",
Assembly.GetExecutingAssembly());
//Remove whitespace
RectangleLength = RectangleLength.Trim();
RectangleBreadth = RectangleBreadth.Trim();
if ( IsNumeric(RectangleLength) && IsNumeric(RectangleBreadth) )
{
try
{
ilength = Convert.ToInt32(RectangleLength,
System.Globalization.CultureInfo.InvariantCulture);
ibreadth = Convert.ToInt32(RectangleBreadth,
System.Globalization.CultureInfo.InvariantCulture);
iPerimeter = 2  * (ilength + ibreadth);
}
catch
{
throw new Exception(string.Format(resmgr.GetString(
"IDS_PERIMETERFUNCTOID_EXCEPTION"),
RectangleLength +  " "  +
RectangleBreadth));
}
}
return iPerimeter.ToString() ;
}

Step 10: Compile and Deploy

You are now ready to build and deploy your functoid. Once it is built, copy the Custom.Biztalk.MathFunctoid.dll to Drive:\Program Files\Microsoft BizTalk Server 2004\Developer Tools\Mapper Extensions.

Now, make the DLL available in the GAC, using the following command line operation:

C:\> gacutil /if Copy the Custom.Biztalk.MathFunctoid.dll

Step 11: Adding the functoid to the ToolBox

Open a BizTalk project and go to toolbox, and then right click on the toolbox. Go to Add/Remove items, select the Functoids tab, and browse to Custom.Biztalk.MathFunctoid.dll in the mapper extension folder, and check it.

You should now see your functoid in the toolbox under the list of Mathematical functoids (because we set the category as Math, remember?).

sample image

Step 12: Take a deep breath!

Congrats, you just finished your first custom BizTalk functoid and I am sure it wont be your last!

Points of Interest

Testing the functoid

I have included a small map to test the functoid. You can download this project in the source available for download at the top of this article. It is titled customFunctoid Map.

sample image

Gotcha's

You cannot insert a bitmap directly into the resource editor, you will have to use ResEditor to do it. The ResEditor can be found here: C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Samples\Tutorials\resourcesandlocalization\reseditor.

Exceptions

You might get an exception that the functoid was not found.

Exception Caught: Functoid not found:
guid({5DE500CC-45BC-454b-A23D-24449899042C})  funcid(6123)

This happens when you GAC the DLL but forget to copy it to the mapper extension folder.

History

  • Version 1.0 - January 22, 2006. published on Code project
  • Posted here on March 28 2006

BTSDeploy Error with property Schema

We recently had a problem with a Biztalk property schema deployment .

When we tried to deploy the schema , We came across this error and had to spend some time trying to debug this one.

The error you get would be a variation of the one below

Property "ns0:Your_Promoted_Property" (msgType="YourSchema#RootNode") not found in Configuration database.

 

Quick Solution

Delete the Node which it is complaining from the property schema and recreate it again

Reasoning

What was odd on our case was this same DLL was deploying in vertain machine but not on some other ones.

After aome amount of gogling I tried to think about the error for some time and this was my line of reasoning . The  deployment was complaining about a promoted property not available in the configuration database . This was a bit weird because the property that Biztalk was complaining about was contained in the same Assembly.

But once I realized that somewhere in the deployment process the properties that were being promoted were first stored into SQL tables for eventual usage in CBR scenario . I realized that this insertion would be failing .  The only reason this could be failing is if the variable already existed.

Since Biztalk being a Globalized product I figured the names would not be used as it is but rather some unique value a Identity  or GUID . So I went ahead and changed the guid value of all the properties that it was complaining , I had edited the XML for this values . (You can delete and recreate the Node if you are not comfortable ) .

Then I rebuilt and it deployed like a charm !

PS: What had happened is one of our Dev's had copied the property schema from another project and changed the namespace and the field name of certain fileds.

This worked on certain machines without problems because these devemachines did not have the solution  from which the property schema was copied deployed on them . Wheras we had this prior solution deployed on our servers.

So I guess Copy-Paste fanatics take care. !

 

My Articles on CodeProject

Been posting some articles on Codeproject  lately .

Check them out

http://www.codeproject.com/script/Articles/list_articles.asp?userid=1913507

Would love to hear your comments on the articles here .

Biztalk Server Podcasts

Listen to Biztalk Server Podcasts from Scott where he talks about Enterprise Service Bus and Windows Workflow Foundation .

Scott answers lot of intersting question here .. like how did he become product manager of Biztalk 2000 code named Latinum .

 While on code names these are the list so far..

Latinum                 BizTalk 2000
Bizet                       BizTalk 2002
Voyager                 BizTalk 2004
Pathfinder             Biztalk 2006
Avalon                    Windows WorkFlow Foundation(WF)
???                         Biztalk 2008

Now that Biztalk Server 2006 is out there and after having seen the demo of Windows Workflow Foundation (WF ) at PDC lot of us are asking what will be future of Biztalk Server 2008 ? . Scott speaks out that the design surface of workflow for WF and BTS was built by the same team and the similarities end there .Biztalk would still be needed to solve problmes of EAI, BPM ,B2B, Adaptor management . Scott also mentions that the workflow for Biztalk 2008 would most probanly share the workflow piece with WF and there would be a upgrade to current customers. This also make me believer the news I heard about the Biztalk and Indigo team at Microsoft got merged into one group . Listen to the Biztalk Server Podcasts here...

Reset Biztalk Passwords

Well we have our enterprise password Resets that happen every 45 days ;Our production servers have passwords that never expire. This causes Havoc to my local biztlak server installation.

THIS information Applies  if you have NOT backed up your master secret
( Thanks  Patrick for pointing out this ) .
i
f you have   in C:\Program Files\Common Files\Enterprise Single Sign-On
>ssoconfig.exe -restoresecret   YouBTSSSOBackupfile

So one day when that password box reaches 2 days to expire you reset that password and suddenly you discover that your biztalk service is not running.

First - Dont Panic !

ok Now you are not panicking :-)
so these are the places you need to reset

Goto ->Start->Run-> Services.msc
and update the password for the following

BizTalk Base EDI service
BiztalkServer Application
Enterprise Single Sign-On Service
MSSQLSERVER
Rule Engine Update Service
SQLSERVERAGENT

Next Open Biztalk Administrator and change passwords for

BizTalk Host Instance Account
BizTalk Isolated Host Instance Account ( In case you set it up same which is not the recommendation btw )

Next Open IIS Manager
Goto ->Start->Run-> inetmgr.msc ->Application pools->Properties ->Identities
and change the password for all the onee below ( You might not have some based on your configuration )

HwsMessagesAppPool
HwsWSAppPool
StsAdminAppPool
STSWebServiceAppPool
TpmWSAppPool (If you are using BAS)
WSSAppPool (Sharepoint app Pool )
BAMAppPool


Whew !! That should get you back on track .
In case it did not leave me a comment or Ping me !

Error while calling Orchestration Exposed as Webservice

If you are trying to call the Orchestration that are exposed as webservice , You will come acros this error below . This usually happens in Dev machines where Biztalk as well as IIS is on the same machine.

 

The Messaging Engine failed to register the adapter for "SOAP" for the receive location "/VirtDir/App.asmx". Please verify that the receive location is valid, and that the isolated adapter runs under an account that has access to the BizTalk databases.

An attempt to connect to "BizTalkMgmtDb" SQL Server database on server "Server" failed with error: "Cannot open database requested in login 'BizTalkMgmtDb'. Login fails

The "SOAP" adapter is suspending an outbound message going to destination URL


 1 ) This issue occurs because the App pool identity that is used by the application pool for the exposed Web service is not added as  to the BizTalk Isolated Host Users group. This is needed because the message needs to get properly authenticated to get submitted.

 2 ) Also this account needs permission to the  %systemroot%\Temp folder on the server that exposes the Web service .This is needed as the web service (.asmx) files are JIT compiled to create DLLs in the %systemroot%\Temp folder.

Giving these correct access and permissions should solve the issue .

 

 

 


BTS2006 : Splitting Messages using Pipeline from Inside the Orchestraion

I had some Aggregator Orchestration which were running into Zombie situations ,
So when I got the biztalk 2006 beta version I was anxious to try out the new functionality of being able to call your receive
pipeline from inside your Orchestration . You can enumerate through the EnvelopeMessage passed into the recieve pipeline
just like you would enumerate in an ICollection or Recordset using .MoveNext() .

This is how my built Orchestration looked like

I will briefly try to capture the steps that I took

1.) Create a Document Schema SingleOrder.xsd

2.) Create an Envelope Schema TotalOrder.xsd

3.) Create a receive Pipeline SplitOrder.btp

 4.) Add the XML Dissasembler and select the Document and envelope Schemas as above.

5.) Create your Recieve Port and set the document type to your Envelope Schema , This Port now has XMLPassthru transmit , I am calling this message IncomingFullMessage

6.) Now we enter Splitting scope ( Pipelines can only be invoked from Atomic scopes, Also it does not support Recoverable interchange processing when called this way )

7.) Add Microsoft.XLANGs.Pipeline as Reference and then ;declare a variable for the pipeline in my case OrderSplitter AS "Microsoft.XLANGs.Pipeline.ReceivePipelineOutputMessages"

8) In the expression Shape Call Order Splitter , OrderSplitter = Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteReceivePipeline(typeof(SplitOrderReceivePipeline),IncomingFullMessage);

9) In the loop Get_Next-Order Shape iterate through each message using OrderSplitter.MoveNext()

10.) Create an Orchestration variable "SingleOrder" of type Document Schema

11.) Create the Single Message you want in the message assignment Shape and set SingleOrder = new System.Xml.XmlDocument(); OrderSplitter.GetCurrent(SingleOrder);

12) Now you have the single Message that you want to process. You can send it to whatever process you want , In this example I am just sending the message to a Output folder.

Biztalk Server 2006 Review - Installation

I started this install on a Virtual PC and I was a bit skeptic if I would be able to finish installation that day , Configuring our development server last time required almost 3 days and another instance I remember configuring a machine with two SQL servers with Analysis server on a different machine almost took a week and a call to MS help desk for some gotcha's .So I was a bit skeptic




One of the first things that you will notice is that there is a set of ways to download all the pre-requisites. Often times in Biztalk Server 2004 , You will have to go and hunt lot of required files like SQL XML , MSXML 4 and SP1 and office Web Components Update and ... Oh You know what I mean . Now the cool thing in BTS 2006 is that you have an one click option of asking Biztalk to download whatever it wants directly off the web or download ONE Cab file containing everything in case your machine is not on the internet or in my case like a VPC



The next thing that one notices is that the whole installation is not one big piece of ALL or NOTHING , wherein some small change or issue would roll back the whole process and you need to go now and manually delete the BizTalk databases at times and that often leads the beginner Biztalk user to give up in frustration .. Also before installation it checks for pre-requisites and tell you what is available and not . Also it asks for one user credentials only if you have a single box scenario. rather than typing the same user name a zillion times

It also shows a smoother progress indication and unlike BTS 2004 , It shows you what is not installed and lets you reconfigure that piece alone later



Overall I must say I am impressed with the setup . The biztalk Server Explorer is completely revamped and now there is a whole concept of artifacts grouped by applications ( Duh !!) , our administrator's are already looking forward to Biztalk 2006


BizTalk Zombies and more..

You have got this error from biztalk "Completed with discarded messages" and are wondering what that means you could be potentially seeing what in BTS buzz world is called a Zombie . A Zombie is usually a valid message or a response that is left without a subscription to process at that point in time . Though this one liner definition is quite crude explanation . If you are dealing with scenarios like Sequential convoys and batching you are likely to witness this especially when you have large amount of transactions and when your system is operating near to high load conditions ( that is when I have witnessed it the most, though there are scenarios for encountering zombies even under little or No load ) .


If you really want to learn more about Zombies read this Blog from Biztalk Core Engine Team


Now If your solution involves a while loop surrounding a listen with one branch having a receive and the other having a delay shape followed by some expression shape that sets the loop counter and controls the loop termination .You would more than likely see this scenario as delay could be triggered and the message could be delivered after.

Now the condition for delay and time out is we don't want to wait for a message forever . So we timeout after an interval (Tn) but this (Tn) is non-deterministic and is usually set to a small number.


For an app that we had increasing the delay from 10 Secs to 2 minutes( chosen at random)
did away with Zombie occurrences . I would also suggest decreasing the default retry of 5 minutes to a lesser value if you are in a aggregated scenario where you are collecting one message at a time. 2 minute looks like a large interval to wait for one message but keep in mind that this delay is not arithmetic and does not occur for each listen . Most often the message is already there to be consumed and this delay happens ONLY when there is no message to consume. In a stressed Biztalk box our scenario which is an EOD movement had given us a liberty of waiting an extra couple of minutes.



Another solution that works is after the loop is over to have another loop with the same correlation set(following) to drain these instances for a certain amount of time ( DRAINING ). You can do this before or after you send out the final message . in the latter case you can send these drained ones as a second message or log them as errors .

Also a WMI event is generated for a Zombie occurrence , I haven't hit across the details of the same .

Biztalk Flat File Performence

Recently I had a scenario which involves processing a large amount of flat files; each of whihc went througha Flatfile Dissasembler before the business processing on that started. Here I record some points of interest of FFDASM behaviour. When FlatFile Disassembler is fed with a large amount of files biztalk waits for all files to unpack before it starts processing.



Our test environment had two boxes each both of which configured under the same host and having identical machine config with SQL on a seperate box was used for the test
For our Scenario we had little over 500 files being dropped simultaneously .The file batch size was set at 20 the default.. It was noticed that after picking up the first 20 and initiating disassembling this batch before the next set is picked up , it goes on picks up all the files.( See graph)

Essentially Biztalk seemed to wait for all the messages to get picked up and then flat file disassembler unpacks all of the flat files from the interchange before it starts processing. This is evident from the apparent lack of activity form the time the last file was picked up and when the first set of files started coming out ( See Graph) . I had seen this in one of prior instance and I recently ran some test and got similar results which made me write this post.


 

Biztalk Flat File Dissasembler Behaviour  

TO "UNDEPLOY" OR "NOT TO UNDEPLOY"

If you have been working with Biztalk for a considerable amount of time like me
you would have gone through the pains of the Undeploy Regac - Deploy loop , Sometime when you are making changes to Schema , it is quite unavoidable but at lot of time you really don't need to , Just re-gacing your dll and restarting the Biztalk service will do the trick . I have not seen a comprehensive documentation for the same . So the list below is mostly from my own experiences

Schemas
=======

Any changes to Schemas like Namespace , Root Node Name , Promoted properties require a UNDEPLOY - DEPLOY Cycle.

Changing a node which is not a promoted one and not a root node , you can get by with just a GAC and restart

The reason for the same is Your Schema#rootnode is used in subscription evaluation , A changes to this without deploy undeploy will give you an subscription not found error


Maps
====
Changing mapping or Functoids in maps DO NOT require a UNDEPLOY - DEPLOY unless the Schema itself has changed ( See schema Above )


Orchestrations
==============
Changes in Orchestration DO NOT require a UNDEPLOY - DEPLOY Cycle unless Send/receive Port shapes are changed

This is mostly because Schemas would change or you add a new port based on a new schema which needs to get updated in the subscription viewer and this requires undeploy - deploy

Pipelines
=========
Changes in Pipeline DO Require a UNDEPLOY - DEPLOY


Assembly
========

External Assembly change DO NOT require a UNDEPLOY - DEPLOY Cycle unless you change the version number

In VB assembly info if the assembly version is set to 1.1.* it will increment the assembly number for every small change. Though it is good from a certain point of view , it can quickly become a pain if you just want to make a little minor change .
So I suggest you control the version number manually , So you can just re-gac the assembly

Please note Gac-ing the change and restart of the BTSservice is needed for all steps

Last but not the least , you should learn ,try and use BTSNANT tool , It is well worth the effort you spent

SEHException While Enlisting Orchestration

I am posting one of the errors we encountered over which considerable time was spent debugging.

You will get the below Error in Event Log


Event Type: Error
Event Source: XLANG/s
Event Category: None
Event ID: 0
Date: 5/5/2005
Time: 3:22:32 PM
User: N/A
Computer: Machine12

Description:
An SEHException exception occurred while the XLANG/s runtime enlisted a service.
Error message:External component has thrown an exception.
Call stack: at Microsoft.BizTalk.MetaDataOM. ICLRType.GetFields(UInt32 dwBindingFlags) at Microsoft.BizTalk.XLANGs.BTXEngine. BTXServiceStaticState._createStringLookup(String svcFullTypeName,
IAssemblyManager asmMgr) at Microsoft.BizTalk. XLANGs.BTXEngine.BTXServiceStaticState. PersistState (String mgmtDBServer, String mgmtDBName, String MsgBoxGroupName, String ApplicationName, String serviceAssembly, String serviceTypeName, Guid[] PortIDs, Guid[] LrpIDs, ITransaction transaction)
at Microsoft.BizTalk.XLANGs. BTXEngine. BTXService.GoLive (String configDBServer, String configDBName, String msgBoxGroupName, String applicationName, String servicePath, String serviceTypeName, Guid[] portIDs, Guid[] lrpIDs, ITransaction transaction)

Exception type: BTXEnlistmentException
Source:
Target Site:
Help Link:
Additional error information:

External component has thrown an exception.

Exception type: SEHException
Source: Microsoft.XLANGs.BizTalk.Engine
Target Site: System.Collections.IEnumerator GetFields(UInt32)
Help Link:
Additional error information:


This normally occurs when you don't have a dependent file of the assembly not in GAC . That is an orchestration which references other Dll's must have the dependencies already GAC'd

Another variation of this enlistment error is OutOfMemory exception which is due to some limitation of WMI , which can be increased with a custom Script


But in our case this was not the case I checked and rechecked the dependencies of our project they were all there .

What we found out was that our Production server did not have Biztalk SP1 applied whereas the dev machine had SP1.

So apparently the issue is still I guess of DLL's Missing in GAC but not of the application but that of Biztalk Later version Assemblies !!

Biztalk Explorer Extension

Wouldnt it be nice to click a DLL and see it's internal schemas and objects contained in a Biztalk DLL , IF you have used ildasm for .net asemblies you know what I am talking about . There is a feature in Biztalk for that , YOu ned to register that dll to get the view in your explorer


The extension is the BtsAsmExt.dll and is located in the \Program Files\Microsoft BizTalk Server 2004\Developer Tools subdirectory.
To enable this functionality
regsvr32 "C:\Program Files\Microsoft BizTalk Server 2004\Developer Tools\BtsAsmExt.dll"

You will see the BizTalk Server Assemblies icon in Windows Explorer alongside the drive letters.



When you click on the BizTalk Server Assemblies you will a list of all of the deployed assemblies. You can then click on each of the assemblies and you will see the BizTalk artifacts that are used in that specific assembly. These includes Orchestrations, Schemas, Maps and Pipelines. In addition, if you double click on an individual artifact, the Type Content Viewer windows pops up and will show you an XML representation.



This tool also includes additional functionality. It adds a BizTalk Server Search pane (found under the View ->Explorer Bar->BizTalk Server Search) which lets you search across the deployed assemblies for any of the BizTalk types. So, I could do a search for any schemas that are referenced by pipelines across all assemblies or Correlation Types referenced by Orchestrations found in assembly X.

Accessing Standard Context properties in Biztalk pipelines like FileName

If you wnated to access context properties in pipelines and have spent needless time figuring out the correct schema for each property here is a comprehensive list

This content is taken as is from <a href="http://blogs.msdn.com/skaufman/"> Stephen Kaufman's WebLog</a>

There are a number of 'built in' promoted properties that provide important information.  There are different items for the receive and send pipelines.

 

The 14 receive pipeline items are (including the associated namespace):

 1.  ReceivedFileName (http://schemas.microsoft.com/BizTalk/2003/file-properties)

 2.  InboundTransportLocation (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 3.  InterchangeID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 4.  ReceivePortID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 5.  ReceivePortName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 6.  WasSolicitResponse (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 7.  AuthenticationRequiredOnReceivePort (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 8.  InboundTransportType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 9.  LRPMsgBodyTracking (http://schemas.microsoft.com/BizTalk/2003/system-properties)

10. MessageExchangePattern (http://schemas.microsoft.com/BizTalk/2003/system-properties)

11. PortName (http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

12. ReceivePipelineID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

13. MessageType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

14. SchemaStrongName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 

While the 31 send pipeline items are

1.  CopyMode (http://schemas.microsoft.com/BizTalk/2003/file-properties)

2.  LTPMsgBodyTracking (http://schemas.microsoft.com/BizTalk/2003/system-properties)

3.  ReceivedFileName (http://schemas.microsoft.com/BizTalk/2003/file-properties)

4.  SPID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

5.  ActualRetryCount (http://schemas.microsoft.com/BizTalk/2003/system-properties)

6.  FileName (http://schemas.microsoft.com/BizTalk/2003/file-properties)

7.  PartyName (http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

8.  ReceivePortName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

9.  WasSolicitResponse (http://schemas.microsoft.com/BizTalk/2003/system-properties)

10. AllowCacheOnWrite (http://schemas.microsoft.com/BizTalk/2003/file-properties)

11. RetryInterval (http://schemas.microsoft.com/BizTalk/2003/system-properties)

12. OutboundTransportCLSID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

13. SPName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

14. InboundTransportLocation (http://schemas.microsoft.com/BizTalk/2003/system-properties)

15. InterchangeID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

16. ReceivePortID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

17. SPTransportID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

18. TransmitPipelineID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

19. AuthenticationRequiredOnReceivePort (http://schemas.microsoft.com/BizTalk/2003/system-properties)

20. InboundTransportType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

21. LRPMsgBodyTracking (http://schemas.microsoft.com/BizTalk/2003/system-properties)

22. MessageExchangePattern (http://schemas.microsoft.com/BizTalk/2003/system-properties)

23. OutboundTransportLocation (http://schemas.microsoft.com/BizTalk/2003/system-properties)

24. PortName (http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties)

25. ReceivePipelineID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

26. SourcePartyID (http://schemas.microsoft.com/BizTalk/2003/system-properties)

27. MessageType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

28. OutboundTransportType (http://schemas.microsoft.com/BizTalk/2003/system-properties)

29. PartNames (http://schemas.microsoft.com/BizTalk/2003/messageagent-properties)

30. RetryCount (http://schemas.microsoft.com/BizTalk/2003/system-properties)

31. SchemaStrongName (http://schemas.microsoft.com/BizTalk/2003/system-properties)

 

 

To get access to these properties you need to get access to the context object.  The following method shell shows how we can do that.

 

public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)

{

IBaseMessageContext context = pInMsg.Context;
.
.
.
}


Now that we have a method to gain access to the context, what if we want to get access to the internal promoted properties?  We can iterate through all of the default promoted properties by using the context.ReadAt method (which produces the list of the items above).  This method takes an index and returns, through 2 out parameters, the name and namespace of the properties. 

We can also use the context.Read method to access the value of each of these promoted properties.  The Read method returns an object type containing the value of the promoted property when passing in the name and namespace of the property.


So, to retrieve the source file name we would use this following line of code:

 

string srcFileName = context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties").ToString();

Biztalk and File Masks Bug /Feature ?

Recently I was debugging a Biztalk solution with a friend of mine Rajesh ,and we noticed a curious Masking issue with BizTalk

Suppose you give a mask

*.XML

Which of these files are picked up ?

A) Orders.xml
B) Orders.XMLTEST
C) Orders.XML.BAK
D) Orders.TXT
E) ORDERS.XMLINFO
F) ORDERS.XML_BACKUP

I am sure your answer is only A , but in reality Biztalk picks up all files except C and D for a mask *.xml

So instead of looking for a file which starts with * and ending with .xml,It seems Biztalk picks up any file which has wild character starts and has .xml in the name not necessarily ending

But the contradiction to that is if there is one more DOT [.] Case C which is not picked up

So the way the mask gets applied is wild character then matches the last Dot and then matches charecters followwing the dot

Is this an intended behaviour or Bug ?

More Posts Next page »