Welcome once again to another BizTalk Server Best practices, Tips, and Tricks blog post! In my previous blog post, I talked about some essential tips and tricks for BizTalk Server administrators:
Today, as I promised, I’m going to speak about another critical Best practice, Tips and Tricks for BizTalk Server developers: Creating Custom Functoids.
Custom Functoids Sandro? really? That is quite basic and easy stuff!
Yep, you are somehow right, but do you know that there is more than one type of Custom Functoids? And do you know that they have different requirements in terms of deployment? Do you know that some of them you don’t need to deploy in other environments than Development?
As you can see, there is more than you probably think about custom functoids
We can consider Functoids as pre-defined functions that we can use to perform complex data manipulations and transformations. Typically on a map, the data is copied from source to destination by dragging links between elements of the two schemes. Functoids stay in the middle of these operations and apply an operation on the incoming data to transform them to the requirements of the destination. The BizTalk Mapper Designer represents a functoid as a box in the middle of the link (or links) between the processing elements.
As a point of interest, functoid is a term coined by Microsoft and is commonly described as “functions on steroids.”
The BizTalk Mapper provides an extensive set of Functoids that can be used in maps, to perform a variety of operations on data that is being mapped from a source instance message to a destination instance message.
By default, the Functoids are organized into nine categories based on their intended purpose:
If you want to know more about Functoids, please check the following resources:
I also recommend you to check the great Pluralsight course created by Dan Toomey: Using Functoids in the BizTalk 2013 Mapper (http://pluralsight.com/training/Courses/TableOfContents/using-Functoids-biztalk-2013-mapper). This course presents a deep-dive exploration of the BizTalk Mapper toolbox, especially the powerful built-in Functoids that enable complex message transformations via drag ‘n’ drop into the design grid.
BizTalk Server allows you to extend the range of operations available within the BizTalk Server mapping environment (aka existing out-of-the-box Functoids). To do that, we call them Custom Functoids.
Although BizTalk Server provides many Functoids to support a range of diverse operations, when you start to create many maps, you will start to realize that some of the custom and small operations or actions, many times using Scripting Functoids, are common in several of your maps. As a consequence, you will find yourself spending your time maintaining several equal code snippets that you normally copy and paste into your maps in several locations inside a map or several maps. It is a good approach to consider transforming code snippets into a custom function. As we mentioned before, Custom Functoids allow you to extend the range of operations available within the BizTalk Server mapping environment. You develop them once, and you can reuse them in several maps! Each custom Functoid is deployed as a .NET assembly using classes derived from Microsoft.BizTalk.BaseFunctoids. And one assembly can contain more than one custom Functoid.
Rather than writing the same inline code (C#, XSLT, and so on) and pasting it in multiple shapes or using a combination of multiple existing Functoids, you can combine them into a Custom Functoid. For example, in the following scenarios:
The advantages of using custom Functoids (or reasons to develop custom Functoids):
Disadvantages or precautions to take when using Custom Functoids:
Don’t write a custom Functoid only to solve a very particular transformation problem. Instead, you should consider using and creating a custom Functoid only to solve a repeat transformation rule that you can reuse in several maps.
If you want to see some examples of custom Functoids, I developed a BizTalk Mapper Extensions UtilityPack, a set of libraries with several useful functoids to include and use in our maps. You can find more details about it here:
Many of you don’t know, but in fact, there are two types of custom Functoids.
Normally people use the SetExternalFunctionName expression to define the action of their custom functoid, something like this:
A good example of this is the BizTalk.Configuration.Functoids available on the BizTalk Mapper Extensions UtilityPack.
In this case, we are basically saying that we will use an external assembly to perform this action, and in this case, this assembly needs to be installed in the GAC in all the environments that you will use this functoid. To add it to the toolbox inside Visual Studio, we also need to add the DLL to the Developer Tools\Mapper Extensions folder under the BizTalk installation path.
This is the best approach when you need to use .NET namespaces that are unavailable to maps or using external DLLs.
But have you already tried to find where out-of-the-box functoids are installed? And probably you didn’t find it. But if you generate the XSLT of your maps and inspect them, you will find a lot of embedded C# code.
Yes, they are SetScriptBuffer functoids. This type of functoid basically tells the BizTalk Mapper to embed the function code inside the XSLT code. They look something like this:
In terms of development effort, it is almost the same. The only differences are that:
The huge advantage of this type of custom Funtoid is that you don’t need to deploy any assembly to your environments. The assembly of this Functoid will only need to be copied to the Developer Tools\Mapper Extensions folder in your developing environment, and you don’t need to install anything in production or other non-development environments.
A good example of this is the BizTalk.String.Functoids available on the BizTalk Mapper Extensions UtilityPack.
Stay tuned for the following BizTalk Server Best practices, Tips, and Tricks.