table of contents
Introduction. 3
Context. 3
Adapter Communication Patterns. 3
Implementation. 4
Design Time. 4
Runtime. 8
Registration. 9
Case study. 10
Conclusions. 10
So when actually you will think of writing a custom adapter?
There are various BizTalk adapters developed by third parties that could be leveraged in your integration project. But what happens if the adapters available do not support the functionality that your solution requires? What if you have your own custom server application that you want to integrate with BizTalk? At this point, you may want to consider building a custom BizTalk adapter using the Microsoft BizTalk Server 2004 Adapter framework.
One of our client’s requirements was, to dynamically send messages to printer based on content; this promoted me to write a custom print adapter for BizTalk Server.
This print adapter is quite similar to SMTP Adapter wherein you can send messages to but does not pull any messages for BizTalk processing.
Adapters play a fundamental role in connecting BizTalk Server 2004 with target applications or technologies. There are three categories of adapters:
· Application adapters like SAP, JDE, PeopleSoft, and Siebel.
· Technology adapters like File, FTP, HTTP, MSMQ, SMTP, and Web services.
· Data Adapters like SQL Server, Oracle, or DB2.
Adapters can also be classified into following category
· In-process adapters, such as the File adapter, execute in the BizTalk Server 2004 process space, called a host instance, which manifests itself as the Windows NT service BTSNTSVC.exe
· Isolated adapters execute in their own process space. You may choose to create Isolated adapters for security reasons or for design reasons. For example, the BizTalk Server 2004 SOAP adapter is implemented as an IIS extension and runs inside the ASP.NET process space rather than the BizTalk Server process space.
Before we delve too far into the details of configuring adapters, it is important for you to understand the way in which an adapter can communicate with BizTalk and other external applications. This will make some of the configuration choices more meaningful when it comes to configuring receive and send ports in the next section.
The BizTalk adapter framework provides a number of communication patterns that can be supported by an adapter, as follows:
· One Way Receive BizTalk receives a message from a wire protocol (File, HTTP, and so on) and passes it off to a receive pipeline, which then persists it to the MessageBox database.
· One Way Send BizTalk picks up a message from the MessageBox database and passes it through a send pipeline, which then sends it out to the appropriate endpoint.
· Request Response BizTalk receives a message in the same way as a One Way Receive, but then the requesting application waits for a response from BizTalk. An example of this type of interaction is exposing an orchestration as a Web service via the SOAP adapter. In this case, a client application sends a request into the SOAP adapter, bound to the orchestration, and then waits for a response.
· Solicit Response BizTalk sends a message to an application in the same way as a One Way Send, but then it waits for a response from the external application. An example of this type of interaction is consuming a Web service within an orchestration via the SOAP adapter. In this case, the orchestration makes a request out to the Web service and then waits for a response.
The BizTalk Server 2004 Adapter framework is an extensible API that sits on top of the underlying BizTalk messaging engine. It provides design-time and runtime interfaces that allow the developer to build a BizTalk adapter. The framework is a COM API that is accessible to managed code via a .NET Primary Interop assembly. The recommended approach for adapter development is to use managed code; therefore, all code samples in this section will be in C#.
I have used Custom Adapter wizard from GotDotNet, now available in BizTalk 2006.
Generally, approach to develop a custom adapter falls broadly into three categories
· Design time
· Runtime
· Registration
This version of Print adapter takes Printer name, font face, font size and document name (appear in printer queue). This can be extended if required.

Following class diagrams are generated using one of VS.NET 2005 new feature.
Print Transmit Adapter class diagram
One should implement UpdateUriForDynamicSend menthod to make adapter dynamic.
Base adapter class diagram
Adapter Management class diagram
Print adapter is One-Way Send just like SMTP adapter
The messaging engine will deliver messages to the send adapter either in IBTTransmitter.TransmitMessage() or IBTTransmitterBatch.TransmitMessage(), depending on whether the adapter is batch aware. Both methods have a Boolean return value that indicates whether the adapter sent the message.
If the adapter returns true, the engine will delete the message from the application queue on behalf of the adapter. If, however, the adapter returns false, the adapter is responsible not only for deleting the message from the application queue, but also for handling any send failures that, for example, require the message to be retried for transmission, suspended, and so on.
For adapters returning false, the TRansmitMessage() implementation should be a nonblocking call and should therefore add the message to a logical queue of messages ready to be sent. The adapter should have its own thread pool, which will service the queue, send the messages, and then notify the engine of the outcome of the transmission.
The message engine threads are typically more CPU bound than the threads used to send data over the wire. Mixing these two types of threads has a negative impact on performance. Nonblocking send adapters enable the decoupling of these two types of thread usage and yield a significant performance improvement
One-way send sequence diagram
For the best performance, send adapters should be nonblocking and batch aware. When the BizTalk FILE adapter was changed from blocking and nonbatch aware to nonblocking and batch aware, a threefold performance gain was realized.
Blocking transmits can cause a performance degradation of an entire host instance because if the send adapter does excessive blocking in transmitMessage(), it will be preventing engine threads from delivering messages to other adapters.
Adapter registration can be done using Adapter Registration Wizard available at SDK or can be done by updating the registry with the appropriate adapter settings via a registry file
Finally you need to add adapter to BizTalk using BizTalk MMC.
This adapter was written of a global investment bank for there message broker application and is successfully deployed with zero defects.
There are many applications and data adapters for BizTalk are available but in live scenarios one can come across to implement a custom functionality which is very specific to business. Thankfully this is yet very generic feature which might required for any business.
I am thankful to John Callaway (the instructor, of BizTalk Deep Dive training courses in the UK) for encouraging me to write a custom adapter for printing.