Creating a Custom Adapter Provider

After a resolver executes, as described in the previous sections, the dynamic resolution service checks whether the result is an endpoint (not a transformation). If it is an endpoint, the service instantiates the adapter manager, which is an instance of the AdapterMgr class.

The adapter manager validates and fixes the transport type and the outbound transport location. If the transport type is still not resolved, and if the URL begins with either "http" or "https", the adapter manager sets the transport type to "WCF-WSHttp".

Next, the adapter manager verifies that the transport type equates to a valid Microsoft BizTalk Server adapter, and then it returns its property namespace. This process runs only once for all adapters and stores the results in a cache to avoid repeated queries for other incoming messages that use the same adapter.

The adapter manager uses the transport type (without the "://" suffix) to determine the appropriate adapter provider. An adapter provider is a custom assembly that must implement the IAdapterProvider interface. The adapter provider uses the properties of the Resolution structure in the Dictionary instance generated by the resolver to set all the protocol-specific properties of the message that enables the Microsoft BizTalk Server run-time engine to perform dynamic resolution.

Like with the resolver (described in the previous section), the dynamic resolution mechanism uses entries in the Esb.config configuration file to locate adapter providers. The following XML shows the section of the configuration file.

<adapterProviders cacheManager= "Adapter Providers Cache Manager"  absoluteExpiration="3600">  
     <adapterProvider name="WCF-WSHttp" type="Microsoft.Practices.ESB.Adapter.WcfWSHttp.AdapterProvider, Microsoft.Practices.ESB.Adapter.WcfWSHttp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22" moniker="Http,Https" />  
     <adapterProvider name="WCF-BasicHttp" type="Microsoft.Practices.ESB.Adapter.WcfBasicHttp.AdapterProvider, Microsoft.Practices.ESB.Adapter.WcfBasicHttp, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22" moniker="Http,Https" />  
     <adapterProvider name="WCF-Custom" type="Microsoft.Practices.ESB.Adapter.WcfCustom.AdapterProvider, Microsoft.Practices.ESB.Adapter.WcfCustom, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22" moniker="mssql" />  
     <adapterProvider name="SMTP" type="Microsoft.Practices.ESB.Adapter.SMTP.AdapterProvider, Microsoft.Practices.ESB.Adapter.SMTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22" moniker="smtp" />  
     <adapterProvider name="FTP" type="Microsoft.Practices.ESB.Adapter.FTP.AdapterProvider, Microsoft.Practices.ESB.Adapter.FTP, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22">  
          <adapterConfig>  
               <add name="DefaultUsername" value="anonymous" />  
               <add name="DefaultPassword" value="" />  
          </adapterConfig>  
     </adapterProvider>  
     <adapterProvider name="MQSeries" type="Microsoft.Practices.ESB.Adapter.MQSeries.AdapterProvider, Microsoft.Practices.ESB.Adapter.MQSeries, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22" moniker="MQS" adapterAssembly="MQSeries, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />  
     <adapterProvider name="FILE" type="Microsoft.Practices.ESB.Adapter.FILE.AdapterProvider, Microsoft.Practices.ESB.Adapter.FILE, Version=2.0.0.0, Culture=neutral, PublicKeyToken=c62dd63c784d6e22" moniker="File" />  
</adapterProviders>  

Creating a Custom Adapter Provider

The adapter manager (an instance of the AdapterMgr class) looks up the adapter provider in the configuration files and loads the appropriate assembly. The dynamic resolution mechanism caches all loaded concrete implementations of the IAdapterProvider interface to avoid repeated reading of configuration information and assembly loading when several incoming messages use the same adapter provider.

Finally, the adapter manager executes the SetEndPoint method of the concrete implementation of the IAdapterProvider interface, and the pipeline component returns the message to the BizTalk Message Box database.

To create a custom adapter provider

  1. Create an assembly that derives from the BaseAdapterProvider base class and contains a SetEndPoint method that sets the endpoint context properties of the message.

  2. Register the adapter provider by adding it to Esb.config configuration files using an <adapterProvider> element with a name for the adapter as the name attribute, the fully qualified name of the class as the type attribute, the moniker as the moniker attribute (multiple values should be separated by a comma), and optionally the assembly of the actual adapter as the adapterAssembly attribute.

  3. Register the new assembly in the global assembly cache.