Last year I did a post on table operations using WCF-SQL Adapter as part of Adapter Pack 2.0. This post was targeted for BizTalk 2009 and I now like to do an update targeting BizTalk Server 2010. With BizTalk Server 2010 (DVD/ISO) comes the adapter pack that bundles old (non-WCF based) Enterprise Adapter for BizTalk with new (WCF-based) adapters to support compatibility with different versions of Line Of Business systems (SAP, Siebel, Oracle, Oracle eBusiness Suite). The BizTalk Adapter Pack 2010 includes support for new versions of the following line-of-business applications and databases: SAP 7, Oracle EBS 12.1 and SQL Server 2008 R2. The Adapter Pack also provides support for Visual Studio 2010 and .NET Framework 4. For documentation see MSDN BizTalk Server Adapter Pack 2010 Documentation and interactive poster.
Installation is straight forward and made simpler through following steps in a wizard and adjusted to installing on x64 (you can read that in post “Installing BizTalk Adapter Pack 2010 on x64”). After installation you will need to add adapter manually if you want to use SQL adapter through a WCF-SQL port. The SQL adapter can be also used in BizTalk as a WCF-Custom port. If you want to use the SQL adapter through a WCF-Custom port, you do not need to add the WCF-Custom port to the BizTalk Server Administration console, because the WCF-Custom port is added to the BizTalk Server Administration console by default. When you use Consume Adapter Service Tool in BizTalk Project it will create xml schema’s based on operation contract (inbound or outbound) and WCF-Custom binding file.
To perform operations on SQL Server through messaging by using the WCF-Custom adapter, you must perform a set of design-time and run-time tasks using Visual Studio and BizTalk Server Administration console respectively. The following high level tasks are required to create a message based solution:
- Create BizTalk project, and generate schema.
- Create messages instances.
- Build and deploy the BizTalk project.
- Configure the application.
- Start the application.
BizTalk Project and generate schema (‘s)
First, we need the XML schemas, which represent our data source. By installing the WCF LOB Adapter SDK, you will have a metadata browser built into Visual Studio. NET at your disposal. You can access this from a BizTalk project by right-clicking the project, choosing Add then Generated Items and selecting Consume Adapter Service.
This action opens a new window that provides us the interface to connect to, browse, and select database objects for service interaction. The very first thing we need to do here is choose the sqlBinding as the service binding, and then configure a connection string. The simplest working connection string consists of an Initial Catalog value for the database, and a valid Server name entry. Note that the adapter now uses a connection string in the form of a URI instead of the traditional Data Source=;Initial_Catalog=;User_ Id=;Password= style.
Once a satisfactory connection string is defined, the Connect button can be clicked to establish an active connection to the target database. If the connection is successful, one see the category browser with a set of database object categories.
On the root "/" character a range of un-typed generic functions are displayed, which can be exploited. Click on tables and you will see a number of Tables, select Products.
Click the Delete, Insert, Select and Update statement in available categories and operations. Click the Add button to add the operations. After clicking the Ok button at the bottom, schemas (and a single binding file) is added to our associated BizTalk project in Visual Studio.NET.
The binding is required later on, when solution is deployed and ports have to be configured for SQL Server (i.e. Send Port). This binding has to be edited for each operation (Select, Update, Insert, and Delete), because there is no corresponding logical ports as this a complete message based solution (if you keep original binding file and import in than you will run into error described in this post Why does the Adapter say ‘Action is not understood’ even though I am using the binding file generated by the ‘Consume Adapter Service’ wizard?). I choose to create four new binding files, each a copy of original, but all with a single operation in BtsActionMapping.
Create message instances
Next step is to generate messages from generated schema, which can be routed from Recieve location in Receive Port to a send port with WCF-Custom Adapter. Generating the first message is easy, as you can right click on the TableOperation.dbo.Products.xsd and select Generate Instance and an instance of top element is created (e.g. Select).
You will get a instance of message as depicted below:
By opening up the TableOperation.dbo.Products.xsd in file-editor you can move the next operation to top, so you can then in Visual Studio generate the next instance for an operation or you can use XML-Editor inside Visual Studio (closing schema, right click and select open with… and then select XML Editor) to move elements around. In end you will have four xml instance for TableOperations, save to file as xml (type all files, encoding UTF-8!).
Build and deploy the BizTalk project
Only schemas are required for a messaging only scenario with WCF-SQL Adapter to perform operations on SQL Server. Therefore after assigning a strong name and application name to BizTalk project it can be build and deployed.
Configure the application
After solution has been deployed it is time to configure the ports. FILE ports are easy and focus here will be configuring the WCF-Custom Send Ports. Through BizTalk Management Console one can browse to BTS.SQL.Table.Operations application and right click the application and select Import Bindings … and navigate to file called WcfSendPort_SqlAdapterBinding_Custom_Select.bindinginfo.xml, select and click Open. You will notice that a Send Port will be created automatically. You can repeat the import for binding:
Next steps are setting filters on WCF-Send Port and File Send Port. Configuration is as follows:
Start the application
In the end your messaging solutions can be depicted as below. After configuration you can start BizTalk application. Schema below gives an overview what will happen once drop message in folder (e.g. In folder).
I hope with this post I was able to show all operations (CRUD) on table. The sample from MSDN shows only SELECT operation and here I have extended on that, showing all operations and how to setup WCF-Custom Adapter using sqlBinding and steps to do, before you can execute all operations on a SQL Table.
You can find sample for this post through MSDN Code Gallery: BizTalk Table Operations – Messaging