Click here to Skip to main content
15,908,175 members
Articles / Programming Languages / C#
Article

Call a custom .NET component from BizTalk 2006

Rate me:
Please Sign up or sign in to vote.
4.29/5 (6 votes)
26 Jun 2008CPOL2 min read 71.4K   18   19
This article describes how to consume a .NET component from an Expression Shape of BizTalk 2006.

Introduction

Lately, I have had to add some external logic to one of my BizTalk applications. I searched all over the web and didn't find a step by step guide to consume a custom .NET component from BizTalk 2006. So, I'm going to enumerate the steps to make a custom .NET component to be implemented from an Expression Shape of BizTalk 2006.

Making the component

  1. Open a new Visual Studio 2005 project. It must be a Class Library.
  2. Input a project name and rename the class name as desired.
  3. Now, it's necessary to add some BizTalk 2006 references in order for both applications to communicate. So, right click in References-->Add Reference, and search in the default installation folder of BizTalk (by default, C:\Program Files\Microsoft BizTalk Server 2006). Add the “Microsoft.XLANGs.BaseTypes.dll” assembly.
  4. basetypes.JPG

  5. Add the following lines on the top of the code of the class:
  6. C#
    using Microsoft.XLANGs.BaseTypes;
    using System.Xml;
  7. Define the class as [Serializable].
  8. Add two methods, one to receive a string, and the other to receive the whole XML message. Both of the methods are going to write the received values to a text file. These methods aren't useful in real world, but are good examples.
  9. C#
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.XLANGs.BaseTypes;
    using System.Xml;
    using System.IO;
    
    
    namespace BizLog
        {
        [Serializable]
        public class Trace
        {
            public void WriteValue(string value)
            {
                File.AppendAllText("C:\\Log.txt", value);
                System.Diagnostics.EventLog.WriteEntry("BizLog", value);
            }
    
            public void WriteMessage(XLANGMessage msg)
            {
                XmlDocument doc = (XmlDocument)msg[0].RetrieveAs(typeof(XmlDocument));
                
                string mystring = doc.InnerXml;
                File.WriteAllText("C:\\content.txt", mystring);
            }
        }
    }
  10. Sign the assembly. First of all, it's necessary to make a file with keys: In the VS2005 Command Prompt, input “Sn –k keyfile.snk”. A new file with keys will be generated. Now, it's necessary to inculcate the project with the new key file. Go to project's Properties-->Signing-->Sign the assembly-->Browse-->keyfile.snk.
  11. In the Solutions Configuration, select “Release” and build the assembly.
  12. Add the component to the GAC (Global Assembly Cache) Start-->Settings-->Control Panel-->Administrative Tools-->Microsoft .NET Framework 2.0 Configuration-->Manage the Assembly Cache-->Add an assembly to the GAC-->Select the assembly.

Calling the component from a BizTalk 2006 orchestration

Let's assume that you have defined a schema project, a message, send port, receive port and all the necessary stuff.

orquestacion.JPG

  1. From the orchestration project, it's necessary to add a reference to the assembly that contains the serializable class we have defined previously.
  2. It's time to create an instance of the new class. Go to “Orchestration View”. Click on Variables. Input the name of the instance and select the type and class, and select the referenced assembly.
  3. type.JPG

  4. Add an Expression Shape to your orchestration and edit the code inside (double click over it). Tip: You can use Ctrl+j or Ctrl+Space to display all the elements you can use as messages, variables, and components.
  5. Add the following code to your Expression Shape:

    expressionshape.JPG

  6. Now, compile the assembly and deploy it. Don't forget to stop the BizTalk application before deploying the assembly, and it's recommended to stop and start the BizTalk Service from Control Panel-->Administrative Tools-->Services.

  7. Start the BizTalk application and send a message to your Receive location. Soon, you will see that two new files have appeared in your hard disk.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Spain Spain
I´ve been working with Oracle, Sql Server and Visual Basic 6 since 2003 and with C# since 2006. Now I´m fighting with Biztalk 2006 too...

MCTS - .NET Framework 4, Windows Applications
MCTS - Accessing Data with .NET Framework 4

Comments and Discussions

 
QuestionError Pin
prasad2007code15-Mar-12 17:05
prasad2007code15-Mar-12 17:05 
AnswerRe: Error Pin
Santiago Sanchez15-Mar-12 21:21
Santiago Sanchez15-Mar-12 21:21 
GeneralObject Reference 'Persona' in Expression Pin
MarvPerk31-Mar-11 11:05
MarvPerk31-Mar-11 11:05 
GeneralRe: Object Reference 'Persona' in Expression Pin
Santiago Sanchez2-Mar-11 23:10
Santiago Sanchez2-Mar-11 23:10 
GeneralRe: Object Reference 'Persona' in Expression Pin
MarvPerk33-Mar-11 16:39
MarvPerk33-Mar-11 16:39 
GeneralRe: Object Reference 'Persona' in Expression Pin
Santiago Sanchez4-Mar-11 4:48
Santiago Sanchez4-Mar-11 4:48 
GeneralRe: Object Reference 'Persona' in Expression Pin
MarvPerk34-Mar-11 7:24
MarvPerk34-Mar-11 7:24 
GeneralRe: Object Reference 'Persona' in Expression Pin
Santiago Sanchez4-Mar-11 7:37
Santiago Sanchez4-Mar-11 7:37 
GeneralRe: Object Reference 'Persona' in Expression Pin
MarvPerk34-Mar-11 8:11
MarvPerk34-Mar-11 8:11 
GeneralCannot get file output to C Drive Pin
Horng Woei Por30-Mar-09 20:26
Horng Woei Por30-Mar-09 20:26 
GeneralRe: Cannot get file output to C Drive Pin
Santiago Sanchez30-Mar-09 23:32
Santiago Sanchez30-Mar-09 23:32 
GeneralRe: Cannot get file output to C Drive Pin
MarvPerk31-Mar-11 11:09
MarvPerk31-Mar-11 11:09 
GeneralException Handling Pin
Aunalisiraj9-Jul-08 18:04
Aunalisiraj9-Jul-08 18:04 
GeneralRe: Exception Handling Pin
Santiago Sanchez10-Jul-08 5:41
Santiago Sanchez10-Jul-08 5:41 
GeneralSpecial point about properties with only get accessors Pin
Hector Contreras2-Jul-08 11:35
Hector Contreras2-Jul-08 11:35 
I'd like to add a special point about properties with only get accessors that might save someone some time...

I needed to use a .NET assembly I downloaded from the web that was a wrapper for GnuPGP. I created a Console Application to test the wrapper. From the test class I was able to set the public properties I needed. For example:

gpgWrapper.homedirectory = strGnuPGHomeDirectory;
gpgWrapper.passphrase = ""; // for encryption, no passphrase is needed
gpgWrapper.originator = ""; // for encryption, no originator is needed
gpgWrapper.recipient = strGnuPGRecipient;
gpgWrapper.command = Commands.Encrypt;

... before calling the ExecuteCommand method to perform the encryption, but when I tried setting those same properties from BizTalk, I could not see them in Intellisense, yet I could see some of the properties and methods. After wasting half a day trying to solve it on my own, I submitted a new thread in Microsoft Discussions Group for BizTalk General (see, "Problem accessing an external .NET assembly from BizTalk") and Dan Rosanova provided the answer.

It turned out that certain properties in the wrapper only had "set" accessors and no "get" accessors. For example:

public string homedirectory
{
set
{
_homedirectory = value;
_bindirectory = value;
}
}

Surprisingly, I was able to access them in the Console Application, but not BizTalk. Dan's suggestion was to either develop a constructor that would set all the properties I needed, or provide get accessors for each of the properties.
GeneralPlease Confirm Necessity of Adding Reference to Microsoft.XLANGs.BaseTypes Pin
Hector Contreras30-Jun-08 3:03
Hector Contreras30-Jun-08 3:03 
GeneralRe: Please Confirm Necessity of Adding Reference to Microsoft.XLANGs.BaseTypes Pin
Santiago Sanchez30-Jun-08 3:11
Santiago Sanchez30-Jun-08 3:11 
GeneralRe: Please Confirm Necessity of Adding Reference to Microsoft.XLANGs.BaseTypes Pin
brett.net30-Jun-08 18:58
brett.net30-Jun-08 18:58 
GeneralRe: Please Confirm Necessity of Adding Reference to Microsoft.XLANGs.BaseTypes Pin
Santiago Sanchez1-Jul-08 9:34
Santiago Sanchez1-Jul-08 9:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.