Click here to Skip to main content
14,691,000 members
Articles » Enterprise Systems » Microsoft BizTalk Server » General
Posted 12 Apr 2011

Tagged as


7 bookmarked


Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
12 Apr 2011CPOL
A BizTalk TCP WCF LOB adapter.


Developers face the challenge of building services that interoperate across organizational and platform boundaries and connect to existing line-of- business (LOB) systems. At the same time, these services and LOB systems evolve independently of each other, making connecting applications and services a constant challenge.


In the early days of BizTalk Server, Microsoft provided a set of adapters that handled the most common external entities such as FILE, SOAP, and HTTP, and when integration value became obvious to the world of business, a new set of adapters were introduced till we reached a point where there was much more than they could provide since the complexity differed from one business to another, and protocols differed too.

So they introduced a new SDK that could be used to develop custom adapters where the added value of this SDK compared to the classic one is that it uses Windows Communication Foundation to communicate with the adapter, which gives us the ability to bind our service to the adapter with not only just protocol and also it can be used in BizTalk and non-BizTalk applications.

Using the code

First you have to download and install WCF LOB Adapter SDK 2.0 from Then open Visual Studio 2005 and click New project, click in Visual C#, and you will find a WCF LOB Adapter template. Select it and click OK. Then you have to go with the wizard shown below.



Click Next.


  • Scheme: Consider it a unique name for the trace logs and prefix for the adapter connection.
  • Project namespace: The actual namespace for the C# application.


The adapter SDK supports two main functionalities along with two sub categories for each functionality:

  • Outbound: From BizTalk to an external location; supports sync and async communication.
  • Inbound: BizTalk will be listening for incoming requests; supports sync and async communication.


By default, the framework supports connection pooling; to make it safer, we will add the enablePooling parameter which will enable or disable the default connection pooling.


Our TCP adapter will have two connection parameters: IP address and port.


public class AdapterBindingCollectionElement : 
      // This class Holds the WCF binding collection
     // No Changes to be applied on this class.

public class AdapterBindingElement : StandardBindingElement
      // This class provides a base class for WCF Binding element
      // No Changes to be applied on this class

public class AdapterBindingElementExtensionElement : BindingElementExtensionElement
    //This class is provided to surface Adapter as a binding element, so that it 
    //can be used within a user-defined WCF "Custom Binding".
    //In configuration file, it is defined under

    //No Changes to be applied on this class

public class AdapterBindingObject : AdapterBinding
      //This is the class used while creating a binding for an adapter

    private void ApplyConfiguration(string configurationName)
        BindingsSection bindingsSection = (BindingsSection)
        AdapterBindingCollectionElement bindingCollectionElement = 
        AdapterBindingElement element = 
        if (element != null)

ApplyConfiguration has to be edited to insert the new custom binding name and location.

public class AdapterConnectionFactory : IConnectionFactory
     //Defines the connection factory for the target system

     private AdapterConnectionUri connection;

    public AdapterConnectionFactory(ConnectionUri connectionUri, 
           ClientCredentials clientCredentials, AdapterCore adapter)
          this.clientCredentials = clientCredentials;
          this.adapter = adapter;
          this.connection = connectionUri as AdapterConnectionUri;
    public AdapterConnectionUri Connection
            return this.connection;

public class AdapterConnectionUri : ConnectionUri
    //This is the class for representing an adapter connection uri
    #region Custom Generated Fields
    private string serverIP = "";
    private int serverPort = 0;
    private UriBuilder uriBuilder;
    #endregion Custom Generated Fields

    // The above fields will be used to build adapter endpoint address
        public AdapterConnectionUri() { Initialize(null); }
    public AdapterConnectionUri(Uri uri): base()
    public override Uri Uri
            return BuildUri();
    // we will override the URI property to build out address,
    // the address should be {scheme://Ipaddress:port}
    // Scheme property can be found the in the adapter core class

public class AdapterCore : Adapter
    //The main adapter class which inherits from Adapter
    public class AdapterCore : Adapter
        // Will be used to hold the adapter operation configuration that will be used
        // in the search, browse and resolver handlers
        internal static XmlDocument operationsRepository = null;
    public AdapterCore(): base(environmentSettings)
        Settings.Metadata.DefaultMetadataNamespace = SERVICENAMESPACE;
        if (operationsRepository == null)
            operationsRepository = new XmlDocument();
            operationsRepository.Load(@"C:\Program Files\Test\" + 
    public AdapterCore(AdapterCore binding): base(binding)
        this.Settings.ConnectionPool.EnablePooling = binding.EnableConnectionPolling;
        this.Settings.Metadata.GenerateWsdlDocumentation = true;
        if (operationsRepository == null)
            operationsRepository = new XmlDocument();
            operationsRepository.Load(@"C:\Program Files\" + 

public abstract class AdapterHandlerBase
    //This is the base class for handlers used
    //to store common properties/helper functions
    protected virtual void Dispose(bool disposing)
        // NOTHING TO DO

public class AdapterMetadataBrowseHandler : AdapterHandlerBase, IMetadataBrowseHandler

    //This class is used while performing a connection-based
    //browse for metadata from the target system
    //This class will use the OperationsConfiguration.xml file

public class AdapterMetadataResolverHandler : AdapterHandlerBase, IMetadataResolverHandler
    //This class is used for performing a connection-based
    //retrieval of metadata from the target system

public class AdapterMetadataSearchHandler : AdapterHandlerBase, IMetadataSearchHandler
    //This class is used for performing a connection-based
    //search for metadata from the target system

public class AdapterConnection : IConnection
    //This class will be hold the actual communication
    //with the LOB in our case it will be
    //TCPClient class

public class AdapterOutboundHandler : AdapterHandlerBase, IOutboundHandler
    // This class will handle the message receiving and we will implement data manipulation.


To deploy the adapter, follow these steps:

  1. Drop the DLL into the GAC.
  2. Drop OperationsConfiguration.xml to "C:\Program Files\Test\LOBAdapters\TCP\".
  3. Open C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\machine.config.
  4. Register the adapter. (Configuration attached in the adapter source.)

Using the adapter in BizTalk

Once the deployment is done, deploy the BizTalk Test project and open the administration console, go to Send ports, and create a new Static Solicit-Response send port. In the transport type, choose WCF-Custom and click Configure.


First add the endpoint address.


Choose the LOBTCPAdapterBinding WCF binding.

Points of interest

Limitation: the TCP message size is limited to 7168 bytes.

This adapter can be called from outside BizTalk Server such as from a WCF service or WWF services.


  • Version 1.0.


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


About the Author

Wael Al Wirr
Program Manager
Jordan Jordan
Self-motivated, creative and results-driven technology executive who is well versed and experienced in leveraging an end-to-end, holistic vision of business objectives to drive full technology / business alignment.

Skilled in grasping business needs and sudden market demand’s shifts by diving into latest business / technology trends, selecting the best fit business model / technology to create a positive reflection on revenue. His multifaceted approach has enabled him to deliver key solutions across a wide range of disciplines including design, development, UX / UI, Business Intelligence.

Technical Specialties are in .Net, Java, Spring Boot, Maven, MS SQL, Oracle, Postgesql, Redis, Javascript, Bootstrap, Angular 2.

Comments and Discussions

QuestionTesting Pin
vasupalli ravi13-Jul-13 5:53
Membervasupalli ravi13-Jul-13 5:53 
AnswerRe: Testing Pin
Wael Al Wirr6-Aug-13 22:16
MemberWael Al Wirr6-Aug-13 22:16 
QuestionSystem.NullReferenceException: Object reference not set to an instance of an object Pin
Larry @Datasmith22-Feb-13 8:11
MemberLarry @Datasmith22-Feb-13 8:11 
AnswerRe: System.NullReferenceException: Object reference not set to an instance of an object Pin
Wael Al Wirr6-Aug-13 22:17
MemberWael Al Wirr6-Aug-13 22:17 
QuestionReceving messages Pin
faisal siddique1-Jan-13 23:13
Memberfaisal siddique1-Jan-13 23:13 
AnswerRe: Receving messages Pin
Wael Al Wirr1-Jan-13 23:24
MemberWael Al Wirr1-Jan-13 23:24 
QuestionAdapterBindingObject issue Pin
sushil_india200025-Dec-12 5:21
Membersushil_india200025-Dec-12 5:21 
AnswerRe: AdapterBindingObject issue Pin
Wael Al Wirr1-Jan-13 23:18
MemberWael Al Wirr1-Jan-13 23:18 
GeneralSend Non-XML with TCP Adapter Pin
Member 204558618-Apr-11 9:12
MemberMember 204558618-Apr-11 9:12 
GeneralRe: Send Non-XML with TCP Adapter Pin
Wael Al Wirr18-Apr-11 20:16
MemberWael Al Wirr18-Apr-11 20:16 
GeneralRe: Send Non-XML with TCP Adapter Pin
Larry @Datasmith22-Feb-13 8:27
MemberLarry @Datasmith22-Feb-13 8:27 
GeneralRe: Send Non-XML with TCP Adapter Pin
mnagisetty4-Oct-11 11:01
Membermnagisetty4-Oct-11 11:01 
GeneralMy vote of 5 Pin
Wael Al Wirr12-Apr-11 2:14
MemberWael Al Wirr12-Apr-11 2:14 
GeneralRe: My vote of 5 Pin
Usman Shaheen17-Apr-11 3:20
MemberUsman Shaheen17-Apr-11 3:20 
GeneralRe: My vote of 5 Pin
Wael Al Wirr17-Apr-11 3:34
MemberWael Al Wirr17-Apr-11 3:34 
GeneralRe: My vote of 5 Pin
Usman Shaheen17-Apr-11 3:48
MemberUsman Shaheen17-Apr-11 3:48 
GeneralRe: My vote of 5 Pin
Wael Al Wirr17-Apr-11 3:54
MemberWael Al Wirr17-Apr-11 3:54 

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.