Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

BizTalk 2010 Recipes : Document Mapping - Creating a Custom Functoid

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
3/28/2011 9:50:15 PM

3.14.1. Problem

You have a mapping need that requires the repeated use of complex functionality.

3.14.2. Solution

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 develop your own custom functoid.

As an example, we'll describe the process to develop, deploy, and use a custom functoid that replaces the ampersand (&), greater than (>), and less than (<) symbols with their HTML/XML equivalents. The functoid will have one input parameter and one output parameter, representing the string on which to run the replacement. This functoid would be used primarily with XML that may be returned from an external source, such as a .NET assembly, where the XML may not have been validated and contains characters that must be escaped.

Use the following steps to create, deploy, and use a custom functoid. Refer to the sample solution SampleCustomFunctoid.sln included with this book.

  1. Create a new Class Library .NET project. Functoids can be coded in any .NET language. This example is implemented in C#.

  2. Add a reference to the Microsoft.BizTalk.BaseFunctoids.dll assembly located in the %\Program Files\Microsoft BizTalk Server 2010\Developer Tools directory.

  3. Create a resource file (resx) to store the functoid configuration parameters. The name of the file and the parameters should match what is shown in Listing 1.

    NOTE

    Adding a bitmap (or any file) to a resource file may require using a third-party application. You can download such applications freely from the Internet.

  4. Code the functoid. The functoid code should match that shown in Listing 1. This is a complete C# class library and will compile into a deployable functoid.

    Example 1. Custom Functoid Class Library
    using System;
    using Microsoft.BizTalk.BaseFunctoids;
    using System.Reflection;

    namespace SampleCustomFunctoid
    {
    /// <summary>
    /// See sample solution (SampleCustomFunctoid.sln)
    /// which accompanies this recipe


    /// </summary>
    [Serializable]
    public class EncodeFunctoid : BaseFunctoid
    {
    public EncodeFunctoid() : base()
    {
    //Custom functoids should begin with 6000 or higher
    this.ID = 6667;

    // resource assembly reference
    SetupResourceAssembly
    ("SampleCustomFunctoid.SampleCustomFunctoidResource",
    Assembly.GetExecutingAssembly());

    //Set the properties for this functoid
    SetName("SAMPLECUSTOMFUNCTOID_NAME");
    SetTooltip("SAMPLECUSTOMFUNCTOID_TOOLTIP");
    SetDescription("SAMPLECUSTOMFUNCTOID_DESCRIPTION");
    SetBitmap("SAMPLECUSTOMFUNCTOID_BITMAP");

    // one parameter in, one parameter out
    this.SetMinParams(1);
    this.SetMaxParams(1);


    //Function code below
    SetExternalFunctionName(GetType().Assembly.FullName,
    "SampleCustomFunctoid.EncodeFunctoid", "EncodeChars");

    //Category in Toolbox where this functoid will appear
    this.Category = FunctoidCategory.String;

    //output of functoid can go to all nodes indicated
    this.OutputConnectionType = ConnectionType.All;

    // add one of the following lines of code for every input
    // parameter. All lines would be identical.
    AddInputConnectionType(ConnectionType.All);
    }


    // Actual function which does the replacement of symbols
    public string EncodeChars(String strInputValue)
    {
    strInputValue = strInputValue.Replace("&","&amp;");
    strInputValue = strInputValue.Replace("<","&lt;");
    strInputValue = strInputValue.Replace(">","&gt;");

    return strInputValue;
    }
    }
    }


  5. Add a strong name key, and build the project.

  6. Place a copy of the assembly in the following directory: %\Program Files\Microsoft BizTalk Server 2010\Developer Tools\Mapper Extensions.

  7. To add the functoid to the toolbox, on the window toolbar, click Tools => Choose Toolbox Items. In the Choose Toolbox dialog box, click the Mapper Functoids tab. Click the Browse button, and select the functoid DLL from step 5, as shown in Figure 1. Then click OK.

  8. Add the functoid to the Global Assembly Cache (GAC).

NOTE

Functoids can be tested in maps without deploying to the GAC.

Figure 1. Adding a custom functoid to the Toolbox

This completes the steps for creating a custom functoid. You can now add the functoid to a BizTalk map and test it. When a map is ready for deployment, the functoid will need to be copied to the Mapper Extensions folder (see step 6) and the GAC on the production server. Figure 2 shows the new functoid with custom bitmap in the toolbox in Visual Studio.

Figure 2. The new functoid in the toolbox

3. How It Works

One of the biggest benefits to using custom functoids is that you have full access to the .NET libraries. Inline code within maps gives only limited access to libraries, and coding is often primitive. Custom functoids are created as .NET class libraries, and they have all of the related coding benefits.

The example shown in this recipe is very simple. Custom functoids do not have to be limited to the two functions shown in the code. For example, assume that you need a functoid that does some sort of interaction with a database. You may need to include an Init() function and a deconstructor to terminate a connection, all of which can be included in the class library.

Additionally, you may need multiple input parameters for your functoid. Additional parameters can be added very easily. See Listing 2 for an example of a functoid with three input parameters.

Example 2. Multiple Input Parameters for a Custom Functoid
SEE CODE FROM Listing 3-20.

// three parameters in, one parameter out
this.SetMinParams(3);
this.SetMaxParams(3);

...

// add one of the following lines of code for every input

// parameter. All lines would be identical.
AddInputConnectionType(ConnectionType.All); // input parameter 1
AddInputConnectionType(ConnectionType.All); // input parameter 2
AddInputConnectionType(ConnectionType.All); // input parameter 3

}

// Actual function which does the replacement of symbols
public string EncodeChars(String strInputValue, strReplace1, strReplace2)
{
strInputValue = strInputValue.Replace("&",strReplace1);
strInputValue = strInputValue.Replace("<",strReplace2);

return strInputValue;
}


Other -----------------
- Windows Server 2008 R2 : Deploying and Using Windows Virtualization - Using Snapshots of Guest Operating System Sessions
- Windows Server 2008 R2 : Deploying and Using Windows Virtualization - Launching a Hyper-V Guest Session
- Windows Server 2008 R2 : Deploying and Using Windows Virtualization - Modifying Guest Session Configuration Settings
- Windows Server 2003 : Using Network Load Balancing (part 2) - Deploying a Network Load Balancing Cluster & Monitoring Network Load Balancing
- Windows Server 2003 : Using Network Load Balancing (part 1) - Planning a Network Load Balancing Deployment
- Exchange Server 2010 : Securing POP and IMAP Exchange Server Traffic
- Securing Exchange Outlook Web App with ISA Server 2006 (part 2) - Creating an Outlook Web App Publishing Rule
- Securing Exchange Outlook Web App with ISA Server 2006 (part 1) - Exporting and Importing the OWA Certificate to the ISA Server
- Leveraging Social Networking Tools in SharePoint 2010 : Restricting User Access to and Creation of My Site Sites
- Leveraging Social Networking Tools in SharePoint 2010 : Reviewing the User Profile Service Application Settings
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
programming4us
Natural Miscarriage
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer