Successfully reported this slideshow.

BizTalk Custom Adapters Toronto Code Camp Presentation


Published on

Slides for the presentation by Moustafa Refaat at Toronto Code Camp 1st May 2010 on how to develop custom BizTalk Adapters

  • Be the first to comment

BizTalk Custom Adapters Toronto Code Camp Presentation

  1. 1. Developing BizTalk Custom Adapters<br />Moustafa Refaat<br />Principle Software Consultant, Genetic Thought<br /><br /><br /><br />
  2. 2. What and Why BizTalk?<br />BizTalk Adapters.<br />Native Custom Adapters<br />WCF Adapters<br />WCF LOB Adapter<br />Introduction<br />2<br /><br />
  3. 3. Business Process Management.<br />Service Oriented Architecture (SOA).<br />Enterprise Services Bus (ESB) platform.<br />Tools and application services that facilitate the rapid creation of integration solutions.<br />Exchange of data in a standard, consistent and reliable way.<br />What is BizTalk<br />3<br /><br />
  4. 4. Why BizTalk?<br />4<br /><br />
  5. 5. BizTalk Hub-Spoke<br />5<br />
  6. 6. Messaging<br />Orchestration engine<br />Business Rule Engine (BRE)<br />Health and Activity Tracking (HAT)<br />Enterprise Single Sign-On (SSO)<br />Business Activity Monitoring (BAM)<br />Business Activity Services (BAS)<br />BizTalk Tools<br />6<br /><br />
  7. 7. How BizTalk Works?<br />7<br /><br />
  8. 8. Messages received<br />Contextual properties. <br />Matching subscriptions. <br />Application-specific queue, instance of a service. <br />Queued messages de-queued designated instances of services.<br />The service handles the message.<br />Publish/Subscribe mechanism<br />8<br /><br />
  9. 9. BizTalk Adapters <br />9<br /><br />
  10. 10. COM or .NET Framework components <br />Transfer messages to and from business end points (such as file systems, databases, and custom business applications) by using various communication protocols (TCP/IP, HTTP, File System, MSMQ, etc).<br />10<br />What is a BizTalk Adapter<br /><br />
  11. 11. Types of BizTalk Adapters<br />Native Adapters FTP, File, SOAP, HTTP<br />WCF Adapters WCF-BASIC, WCF-HTTP ..<br />WCF LOB Adapters<br />www.<br />
  12. 12. BizTalk and Service Orientation<br />Expose all different types of adapters through WSDL and XSD metadata documents that describe the adapter’s messaging contracts. <br />With BizTalk adapter framework create a custom adapter that can be consumed in BizTalk as existing BizTalk adapters through a consistent, service-oriented, model that relies on WSDL and XSD metadata artifacts<br />www.<br />12<br />
  13. 13. BizTalk Adapters<br />"native" or "integrated" adapters <br />FILE, FTP, HTTP, MQSeries, MSMQ, POP3, SMTP, SOAP, SQL, Windows Sharepoint Services<br />WCF Adapters<br />WCF-WSHttp, WCF-BasicHttp, WCF-NetTcp, WCF-NetMsmq, WCF-NetNamedPipe, WCF-Custom, and WCF-CustomIsolated<br />www.<br />
  14. 14. Adapters Function<br />Associated with a receive location designed to listen for messages from a certain transport at a certain address. <br />Message is received by the receive location, it is passed to the adapter. <br />The adapter <br />attaches the data stream to the message, <br />adds any metadata pertaining to the endpoint that the data was received from,<br />submits that message into the BizTalk Messaging Engine<br />www.<br />
  15. 15. Message Exchange Patterns<br />One-Way (Asynchronous)<br />Request-Response Style Protocols<br />Solicit-Response Style Protocols. <br />Request-Multiresponse.<br />Loop-Back. <br />15<br /><br />
  16. 16. Hosting the adapter <br />In-process (BTSNTSrvc.exe).<br />Send and Receive.<br />Instantiate the adapter<br />Transport prox.<br />Services the adapter's requests.<br />Terminates the adapter.<br />Adapter and endpoint configuration.<br />Isolated adapters (out of Process)<br />Receive only.<br />16<br /><br />
  17. 17. Why write a custom Adapter<br />Specific custom application <br />Use a protocol for which a native adapter does not exist<br />Writing a custom adapter is challenging exercise. <br />Adapter Framework simplifies custom adapter development<br />Sample adapter source code in the BizTalk Server SDK.<br />17<br /><br />
  18. 18. Types of Custom Adapters <br />Native Custom Adapter<br />WCF Custom Adapter<br />WCF LOB Custom Adapter<br />www.<br />
  19. 19. The Adapter Framework<br />Microsoft.BizTalk.Adapter.Framework interfaces enable adapters to:<br />Provide a means to modify configuration property pages. <br />Import services and schemas into the BizTalk project. <br />19<br /><br />
  20. 20. Adapter Framework Tools<br />Administration console<br />BizTalk Explorer<br />20<br /><br />
  21. 21. Adapter Framework Tools<br />Metadata Wizard<br />Property Pages<br />21<br /><br />
  22. 22. Adapter Framework Components<br />IBaseMessage Interface<br />Create a message to pass to the Messaging Engine. <br />One or more message parts represented by the IBaseMessagePart interface. <br />Each message part has an IStream interface pointer. <br />Context of a message is IBaseMessageContext interface<br />www.<br />
  23. 23. Adapter Framework Components<br />Messaging Engine Interfaces<br />IBTTransportProxy Transport proxy, creating batches, getting the message factory, and registering isolated receivers with the engine. <br />IBTTransportBatch defines methods that adapters can use to operate on batches of messages. <br />The Messaging Engine processes batches asynchronously.<br />IBTDTCCommitConfirm for MSDTC transactions.<br />www.<br />23<br />
  24. 24. Adapter Framework Components<br />Adapter Interfaces<br />IBaseComponent: Name, Version, and Description of the adapter.<br />IBTTransport: Transport Type and ClassID of the adapter.<br />IBTBatchCallback: callback interface through which the adapter receives status and error information for a batch of messages it submits to the Messaging Engine.<br />IPersistPropertyBag(optional): configuration interface through which handler configuration is delivered to the adapter. <br />IBTTransportControl(Optional): used to initialize and terminate an adapter not required for isolated adapters.<br />www.<br />24<br />
  25. 25. IPropertyBag<br />void Read ([InAttribute] string propName,<br /> out Object ptrVar, interrorLog)<br />void Write ( [InAttribute] string propName, [InAttribute] ref Object ptrVar )<br />www.<br />
  26. 26. Adapter Components <br />AdapterRegistryWizard.exe <br />Design-Time Component <br />Run-Time Component <br /><br />26<br />
  27. 27. Adapter Instantiation <br /><br />27<br />
  28. 28. Practical Adapter Development<br />Program Files (x86)Microsoft BizTalk Server 2009SDKSamplesAdaptersDevelopment<br />BizTalk Adapter Wizard<br />www.<br />28<br />
  29. 29. The Unzip Adapter<br /><br />29<br />
  30. 30. Packages<br />www.<br />30<br />
  31. 31. UnzipAdapter<br />www.<br />31<br />
  32. 32. ProcessMessage Method<br />///<summary><br /> /// Implementation for AsyncTransmitterEndpoint::ProcessMessage<br />/// Transmit the message and optionally return the response message (for Request-Response support)<br />///</summary><br />public override IBaseMessageProcessMessage(IBaseMessage message)<br /> {<br />IBaseMessage result = null;<br />Stream source = message.BodyPart.Data;<br />// build url<br />UnzipTransmitProperties props = new UnzipTransmitProperties(message, propertyNamespace);<br />// string filePath = FaxAdapterTransmitProperties.CreateFileName(message, props.Uri);<br />UnzipManager um = new UnzipManager(props.TargetDirectory);<br />um.UnzipStream(source);<br />return result;<br /> }<br />www.<br />
  33. 33. Transmst Handler Send Adapter<br />www.<br />
  34. 34. Transmit Location Send Port<br />www.<br />
  35. 35. The Adapter Management Part<br />public string GetConfigSchema(ConfigType type)<br /> {<br /> switch (type)<br /> {<br /> case ConfigType.ReceiveHandler:<br /> return null;<br /> case ConfigType.ReceiveLocation:<br /> return null;<br /> case ConfigType.TransmitHandler:<br /> return GetResource("MoustafaRefaat.UnzipAdapterManagement.TransmitHandler.xsd");<br /> case ConfigType.TransmitLocation:<br /> return GetResource("MoustafaRefaat.UnzipAdapterManagement.TransmitLocation.xsd");<br /> default:<br /> return null;<br /> }<br /> }<br />www.<br />
  36. 36. How to Deploy a Custom Adapter<br />C:Program Files (x86)Microsoft BizTalk Server 2009SDKUtilitiesAdapterRegistryWizard<br />www.<br />
  37. 37. Windows Registry<br />www.<br />
  38. 38. Adapters Framework Final Notes<br />BizTalk adapter framework <br />Tremendous business value in complex environments<br />Adapters to be consumed within BizTalk Server Only. <br />You cannot consume a BizTalk adapter from traditional .NET code. <br /><br />38<br />
  39. 39. WCF Adapters<br />WCF-WSHttp adapter. WS-* standards WS-Transaction WS-Security <br />WCF-BasicHttp adapter. ASMX WS-I Basic Profile 1.1. <br />WCF-NetTcp adapter. WS-* standards support over the TCP transport. <br />WCF-NetMsmq adapter. Microsoft Message Queuing (MSMQ) <br />WCF-NetNamedPipe adapter. on-machine cross-process communication. <br />WCF-Custom adapter. WCF extensibility features.<br /> select and configure a WCF binding and the behavior information for the receive location and send port. <br />WCF-CustomIsolated adapter. WCF extensibility features over the HTTP transport. <br />select and configure a WCF binding and the behavior receive location running in an isolated host.<br />www.<br />
  40. 40. WCF bindings <br />A binding in WCF is responsible for “binding” the logical messages used within the service layer to the underlying channel layer. <br />A binding defines all of the details around how a message will be processed between your .NET service code and the underlying network or communication medium that’s used to transmit the message. <br />Specify security processing, <br />message encoding, <br />a transport channel details. <br />www.<br />
  41. 41. WCF Adapters Benefits<br />Support for WS-* <br />Richer “pipeline” model for manipulating messages as they move in and out of the server. <br />WCF services can be consumed from any .NET application (NOT restricted to BizTalk). <br />www.<br />
  42. 42. WCF Services<br />www.<br /><ul><li>Consume and expose services using WCF within the BizTalk port architecture. </li></li></ul><li>BizTalk LOB Adapter Pack<br />Oracle<br />Oracle E-Business Suite<br />mySAP Business Suite<br />Siebel eBusiness Applications<br />Microsoft SQL Server<br />www.<br />
  43. 43. Service-enablement Issues<br />Consume any LOB application that has been service-enabled. A service façade that provides WSDL and XSD metadata. <br />How to effectively expose metadata to the consumer. <br />Some applications expose a vast underlying data source<br />impossible to serve up a single WSDL<br /> The consumer “what data” they’re interested in up front and generate specialized metadata files for that particular usage.<br />Impact the performance and throughput of the system. <br />HTTP and XML negative effect<br />WCF LOB Adapter SDK provide a simplified and unified model for creating custom BizTalk adapters that can be used from any WCF client application including BizTalk Server. <br />The SDK makes it much easier to provide metadata-driven adapters that can embrace native LOB protocols and formats when necessary.<br />www.<br />
  44. 44. Consuming WCF LOB Adapters<br />Add Adapter Service Reference plug-in<br />Consume Adapter Service Reference plug-in<br />www.<br />
  45. 45. When Should I Write a Custom LOB Adapter?<br />Do not if<br />A Web service façade already exists<br />An adapter already exists<br />transport such as FTP or SMTP<br />Do if<br />LOB application expose multiple operations and a wide variety of data <br />Different consumers need to consume your LOB application differently?<br />LOB application have native programming interfaces or protocols<br />www.<br />
  46. 46. Building Custom Adapters with the WCF LOB Adapter SDK<br />metadata support<br />connection management<br />message handling<br />www.<br />
  47. 47. Steps for Building a Custom Adapter <br />Choose a protocol scheme for the custom adapter (e.g., “myhttp://…”)<br />Decide on the directionality (outbound vs. inbound) and whether it needs to be asynchronous.<br />Decide on the metadata options your custom adapter will provide.<br />Identify any adapter properties you’ll want to expose for end-user customization.<br />Run the WCF LOB Adapter Development Wizard and specify your choices.<br />Familiarize yourself with the generated Visual Studio solution.<br />Finish implementing the provided connection, metadata, and runtime classes.<br />www.<br />
  48. 48. Using the WCF LOB Adapter Development Wizard<br />www.<br />
  49. 49. WCF LOB Adapter Wizard<br />www.<br />
  50. 50. WCF LOB Adapter Wizard<br />www.<br />
  51. 51. Handler and Endpoint schemas<br />www.<br />
  52. 52. Generated Project<br /><br />
  53. 53. Implementing the Connection and Binding Classes<br />The connection factory class has a default implementation that will create connections when requested by the Adapter SDK runtime <br />The connection URI class requires you <br />implement Uri parsing logic<br />write the LOB-specific connection code. <br />manage the opening and closing of connections to the LOB system. <br />ClearContext method to prepare a connection object to be put back in the pool. <br />IsValid method to return a status indicating whether the open connection is in a valid state or not. <br />The four binding-related classes provide the WCF packaging that makes the adapter easy to use. <br />A binding class, <br />A binding element, <br />and A binding element extension supplied in the new project wizard all the way from the configuration up to the adapter class itself<br />www.<br />
  54. 54. Implementing the Metadata Classes<br />The browse and search classes <br />One method return array of MetadataRetrievalNode objects representing the operations that can be performed on the adapter. <br />Definitions of named items that can be shown to a developer using the adapter <br />You’ll need to do your mapping to the LOB system. <br />The metadata resolver is responsible for resolving metadata identifiers to operation descriptions. <br />www.<br />
  55. 55. Implementing the Remaining Runtime Classes<br />The outbound handler execute method receives a WCF message object and is expected to return the same. <br />Where the real communication happens. <br />Handler might need: <br />a connection and <br />metadata to provide information about a specific operation. <br />Base class for the handler provides the connection and a MetadataLookup object that can be used to query for metadata. <br />You to decide how to translate that information into an LOB API call, and how to translate the result back into a WCF Message object. <br />www.<br />
  56. 56. Implementing the Remaining Runtime Classes<br />The inbound handler is complicated <br />Begin listening for messages <br />get them into the system when they arrive. <br />Implement StartListener and StopListener to control when the adapter should start or stop whatever specific mechanism it has for receiving messages. <br />WaitForMessage<br />TryReceive. <br />www.<br />
  57. 57. Custom Adapters<br /><br />
  58. 58. WCF LOB Custom Adapters<br /><br />
  59. 59. Questions<br /><br />
  60. 60. Conclusion<br />Writing Custom adapters is not an easy task but not hard<br />You can write custom<br />Native BizTalk Adapters<br />WCF extensions in WCF-CUSTOM adapter<br />Custom WCF LOB Adapter<br />www.<br />
  61. 61. Thanks to our contributors<br />