WCF LOB Adapter

Here are some tips for building the custom WCF LOB Adapter leant in the past days…

§ Design time

§ xxxURL.cs: This is where the custom connection string will go, i.e. for my scenario, the binding string is fax://faxserver/?enableTracing, the schema is fax, the fax server is host, enable tracing is custom query parameter which is then passed to a property field

  • § Add and expose a variable of type URLBuilder. However, this field is not required, as long as there is any custom logic to parse the url connection string
  • § Add all the properties required for the end system

§ xxxFactory.cs: This is where the factory class to create the xxxConnection class

  • § declare a lob server wrapper instance, this instance will be used to act as proxy access the end system methods
  • § declare a xxxURL instance, this is used to access connection properties
  • § declare a ClientCredentials instance, this is used to access authentication information

§ xxxConnection.cs: This is where the WCF framework manages connection, providing open(), close(), abort() etc.

§ xxxBindingElement.cs: This is where declaring the binding properties

clip_image001

§ xxxBroswseHandler.cs: This is where the end system is surfaced. i.e for my fax adapter, I am planning to surface the ‘SendFax’ as outbound operation, ‘ReceiveFax’ as inbound operation. To surface a limited rather static operation, essentially just evaluate the passed in NodeID and return a list of MetadataRetrievalNode variables. The MetadataRetrievalNode variable will describe the method name, direction. I used the xml namespace in representing the node ID, i.e. the SendFax operation node ID is http://faxservice.mypoc.com/action/sendfax

clip_image002

§ xxxResolveHandler.cs: The framework calls this class to resolve the adapter contracts. For BizTalk, this is where the magic of incoming and outgoing schema generated. For my case, I have a SendFax as inbound type, SendFaxResponse as response type.

§ Define the inbound and outbound schema

clip_image003

§ Note 1: the schema has to define a global type, like above. These XSD schema files should be compiled as embedded resources.

§ Note 2: the schema has to has a corresponding class deriving TypeMetadata.

clip_image004

clip_image005

§ Note 3: inbound parameter, a OperationParameter has to be defined to referncing the XSD global type, and the ComplexQualifiedType for ResovleTypeMetadata() to parse

clip_image006

§ Note 4: outbound parameter,  the XSD subclassed to be passed to extraTypeMetadataResolved

§ Runtime: the runtime is rather simple,

§ A simple rule, the inbound message <displayname><parameter name>{data}</parameter name></displayname; the outbound response  <SendFaxResponse><SendFaxResult>{Name}</SendFaxResult></SendFaxResponse>

§ Message property access is rather simple, as WCF framework will copy the WCF message values to and from the BizTalk IBaseMessage

clip_image007

§ Deployment: change the <system.serviceModel> section of machine.config for 32 bit or 64 bit (per BizTalk host instance setting). Add <behaviorExtensions>, <bindingElementExtensions> and <client>\<endpoint>