Calling a .net component from BizTalk orchestration

This blog is to explain how to call C# components from BizTalk. I am going to explain this scenario by taking simple example like Addition of two number in C# component and call the C# method from BizTalk Orchestration.

First, we need to create a C# class library by following below steps.

  1. Start–>VisualStudio–>Click on Visual Solution–>File–>New–>Project
  2. Select class library project from the template “Visual C#” like below.


3. Change the project name “ClassLibrary1” to “SumofTwoNumbers” and then click OK.

4. Change the class name from “Class1.cs” to “Sum.cs”.

5.Add below code in .cs file


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace SumofTwoNumbers



   public class Sum


        public Int32 Addition (Int32 Num1, Int32 Num2)


            Int32 Add;

            Add = Num1 + Num2;

            return Add;       




This C# component takes two input parameter and return the sum of the two parameters. These two input parameters need to be passed from BizTalk orchestration for our scenario.

Note: Make sure class should be ‘Serializable’, because when calling instances of class, not marked as Serializable from an orchestration, it must be from an atomic scope. 

6. Provide strong name key for the project and Build it.

7. Once you build the project, one dll gets created in project directory, you need to GAC the dll by using GACUtils tool.

8. Now C# dll is ready to use from BizTalk orchestration.

Follow below steps to create BizTalk application and call above C# method.

9. Create a BizTalk project and add above C# library as reference to the project.


10. Open BizTalk orchestration–>Goto Orchestration view–>Create a new variable name “SumOfTwoNumbersMethod”–>Open Properties of the variable–>Type–>Select <.Net Class..>–>Select project name–>Select Classname from the References.

11. Now we have a BizTalk variable ready which points to the C# class.

12. Now we can use this variable in BizTalk expression shape to pass the input parameters to the method.


//SumOfTwoNumbersMethod—This is the variable which we created above, to point to the C# class.

//Addition—This is the C# method where we have our actual logic.

//InputMsg.Val1—This is the first input parameter to the C# method.

//InputMsg.Val2—This is the second input parameter to the C# method.

//SumOutput – This is the int data type variable which stores the output of the method.

13. Now we have method output stored in the variable “SumOutput”, we can use this variable according to our requirement in the orchestration.


2 thoughts on “Calling a .net component from BizTalk orchestration

  1. When creating an assembly that will be used by BT, it is appropriate to mark all classess as serializable. Since Biztalk is stateless and make use of persistence points, which details are stored in BT SQL server DB by serializing all the data. Therefore non serializable classes or type can’t be used directly in orchestration BTW it can be used in orchestration but in an atomic scope only…

    Nice example and would you mine to have your all you projects files on Github ? ..Thanks


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s