BizTalk 2009 - Custom Functoid Wizard

Posted by StuartBrierley on Geeks with Blogs See other posts from Geeks with Blogs or by StuartBrierley
Published on Wed, 26 May 2010 07:19:29 GMT Indexed on 2010/05/26 8:33 UTC
Read the original article Hit count: 263

Filed under:

When creating BizTalk maps you may find that there are times when you need perform tasks that the standard functoids do not cover.  At other times you may find yourself reapeating a pattern of standard functoids over and over again, adding visual complexity to an otherwise simple process. 

In these cases you may find it preferable to create your own custom functoids. 

In the past I have created a number of custom functoids from scratch, but recently I decided to try out the Custom Functoid Wizard for BizTalk 2009.

After downloading and installing the wizard you should start Visual Studio and select to create a new BizTalk Server Functoid Project.

BizTalk 2009 New Project

BizTalk 2009 Custom Functoid Wizard

Following the splash screen you will be presented with the General Properties screen, where you can set the classname, namespace, assembly name and strong name key file.

BizTalk 2009 Custom Functoid Wizard General Properties

The next screen is the first set of properties for the functoid.  First of all is the fuctoid ID; this must be a value above 6000. You should also then set the name, tooltip and description of the functoid.  The name will appear in the visual studio toolbox and the tooltip on hover over in the toolbox.  The descrition will be shown when you configure the functoid inputs when using it in a map; as such it should provide a decent level of information to allow the functoid to be used.

BizTalk 2009 Custom Functoid Wizard Functoid Properties

Next you must set the category, exception mesage, icon and implementation language.  The category will affect the positioning of the functoid within the toolbox and also some of the behaviours of the functoid.

BizTalk 2009 Custom Functoid Wizard Functoid Properties Continued

We must then define the parameters and connections for our new functoid.  Here you can define the names and types of your input parameters along with the minimum and maximum number of input connections.  You will also need to define the types of connections accepted and the output type of the functoid.

BizTalk 2009 Custom Functoid Wizard Functoid Parameters and Connections

Finally you can click finish and your custom functoid project will be created.

BizTalk 2009 Custom Functoid Wizard Final

The results of this process can be seen in the solution explorer, where you will see that a project, functoid class file and a resource file have been created for you.

BizTalk 2009 Custom Functoid Wizard Solution Explorer

If you open the class file you will see that the following code has been created for you:

The "base" function sets all the properties that you previsouly detailed in the custom functoid wizard.

 public TestFunctoids():base()
 {
   int functoidID;
   // This has to be a number greater than 6000
   functoidID = System.Convert.ToInt32(resmgr.GetString("FunctoidId"));
   this.ID = functoidID;

   // Set Resource strings, bitmaps
   SetupResourceAssembly(ResourceName, Assembly.GetExecutingAssembly());
   SetName("FunctoidName");                 
   SetTooltip("FunctoidToolTip");
   SetDescription("FunctoidDescription");
   SetBitmap("FunctoidBitmap");

   // 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,
    "MyCompany.BizTalk.Functoids.TestFuntoids.TestFunctoids", "Execute");

   // Category for this functoid.
   this.Category = FunctoidCategory.String;

   // Input and output Connection type
   this.OutputConnectionType = ConnectionType.AllExceptRecord;
   AddInputConnectionType(ConnectionType.AllExceptRecord);
  }

The "Execute" function provides a skeleton function that contains the code to be executed by your new functoid.  The inputs and outputs should match those you defined in the Custom Functoid Wizard.

  public System.Int32 Execute(System.Int32 Cool)
  {
   ResourceManager resmgr = new ResourceManager(ResourceName, Assembly.GetExecutingAssembly());
   try
   {
    // TODO: Implement Functoid Logic
   }
   catch (Exception e)
   {
    throw new Exception(resmgr.GetString("FunctoidException"), e);
   }
  }

Opening the resource file you will see some of the various string values that you defined in the Custom Functoid Wizard - Name, Tooltip, Description and Exception.

BizTalk 2009 Custom Functoid Wizard String Resources

You can also select to look at the image resources.  This will display the embedded icon image for the functoid.  To change this right click the icon and select "Import from File".

BizTalk 2009 Custom Functoid Wizard Image Resources

Once you have completed the skeleton code you can then look at trying out your functoid. To do this you will need to build the project, copy the compiled DLL to C:\Program Files\Microsoft BizTalk Server 2009\Developer Tools\Mapper Extensions and then refresh the toolbox in visual studio.
 

© Geeks with Blogs or respective owner