Click here to Skip to main content
15,867,488 members
Articles / Productivity Apps and Services / Biztalk

TCP WCF LOB Adapter

Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
11 Apr 2011CPOL2 min read 42.3K   714   7   17
A BizTalk TCP WCF LOB adapter.

Introduction

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.

Background

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 http://www.microsoft.com/downloads/en/details.aspx?FamilyID=56278fde-b708-469c-987e-ded9c6c5e580. 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.

1.JPG

2.JPG

Click Next.

3.JPG

  • 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.

4.JPG

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.

5.JPG

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.

6.JPG

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

7.JPG

C#
public class AdapterBindingCollectionElement : 
       StandardBindingCollectionElement<AdapterBindingObject,AdapterBindingElement>
{
      // 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)
          System.Configuration.ConfigurationManager.GetSection(
          "system.serviceModel/bindings");
        AdapterBindingCollectionElement bindingCollectionElement = 
          (AdapterBindingCollectionElement)
          bindingsSection["LOBTCPAdapterBinding"];
        AdapterBindingElement element = 
          bindingCollectionElement.Bindings[configurationName];
        if (element != null)
        {
              element.ApplyConfiguration(this);
        }
    }
}

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

C#
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
    {
        get
        {
            return this.connection;
        }
    }
}

public class AdapterConnectionUri : ConnectionUri
{
    //This is the class for representing an adapter connection uri
    #region Custom Generated Fields
    private string serverIP = "127.0.0.1";
    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()
    {
        Initialize(uri);
    }
    public override Uri Uri
    {
        get
        {
            return BuildUri();
        }
        set
        {
            ParseUri(value);
        }
    }
    // 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\" + 
               @"LOBAdapters\TCP\OperationsConfiguration.xml");
        }
    }
    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\" + 
              @"Test\LOBAdapters\TCP\OperationsConfiguration.xml");
        }
    }
}

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.
}

Deployment

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.

8.JPG

First add the endpoint address.

9.JPG

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.

History

  • Version 1.0.

License

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


Written By
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 4:53
vasupalli ravi13-Jul-13 4:53 
AnswerRe: Testing Pin
Wael Al Wirr6-Aug-13 21:16
Wael Al Wirr6-Aug-13 21:16 
QuestionSystem.NullReferenceException: Object reference not set to an instance of an object Pin
Larry @Datasmith22-Feb-13 7:11
Larry @Datasmith22-Feb-13 7:11 
AnswerRe: System.NullReferenceException: Object reference not set to an instance of an object Pin
Wael Al Wirr6-Aug-13 21:17
Wael Al Wirr6-Aug-13 21:17 
QuestionReceving messages Pin
faisal siddique1-Jan-13 22:13
faisal siddique1-Jan-13 22:13 
AnswerRe: Receving messages Pin
Wael Al Wirr1-Jan-13 22:24
Wael Al Wirr1-Jan-13 22:24 
QuestionAdapterBindingObject issue Pin
sushil_india200025-Dec-12 4:21
sushil_india200025-Dec-12 4:21 
AnswerRe: AdapterBindingObject issue Pin
Wael Al Wirr1-Jan-13 22:18
Wael Al Wirr1-Jan-13 22:18 
GeneralSend Non-XML with TCP Adapter Pin
Member 204558618-Apr-11 8:12
Member 204558618-Apr-11 8:12 
GeneralRe: Send Non-XML with TCP Adapter Pin
Wael Al Wirr18-Apr-11 19:16
Wael Al Wirr18-Apr-11 19:16 
GeneralRe: Send Non-XML with TCP Adapter Pin
Larry @Datasmith22-Feb-13 7:27
Larry @Datasmith22-Feb-13 7:27 
GeneralRe: Send Non-XML with TCP Adapter Pin
mnagisetty4-Oct-11 10:01
mnagisetty4-Oct-11 10:01 
GeneralMy vote of 5 Pin
Wael Al Wirr12-Apr-11 1:14
Wael Al Wirr12-Apr-11 1:14 
GeneralRe: My vote of 5 Pin
Usman Shaheen17-Apr-11 2:20
Usman Shaheen17-Apr-11 2:20 
GeneralRe: My vote of 5 Pin
Wael Al Wirr17-Apr-11 2:34
Wael Al Wirr17-Apr-11 2:34 
GeneralRe: My vote of 5 Pin
Usman Shaheen17-Apr-11 2:48
Usman Shaheen17-Apr-11 2:48 
GeneralRe: My vote of 5 Pin
Wael Al Wirr17-Apr-11 2:54
Wael Al Wirr17-Apr-11 2: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.