BizTalk 2010 XML Polling with WCF-SQL Adapter

One of the feature that came with the WCF-SQL Adapter was the ability to XML polling from SQL.  Anyone that remembers the original SQL adapter from BizTalk remembers the requirement for all the data returned from SQL to have the FOR XML AUTO added to the end of the query and the XMDATA added to add the Store Procedure call to your BizTalk project.

Typically when you poll data out of SQL it is a single table or the output of a stored procedure, this limited the type of data that could be returned, the example is that it was difficult to return the order header and all the detail lines with a single polling statement.  The XML polling feature of the WCF-SQL adapter allow you to create your own XML document in SQL and return it to BizTalk via a polling statement.

In this blog post I am going to show how to do this.

Background

I will be using the Sample AdventureWorks database and returning and Order XML document.

Install the AdventureWorks SQL sample database from http://sqlserversamples.codeplex.com/

Install the BizTalk 2010 LOB Adapter SDK and the LOB Adapter Pack (in not already installed)

In SQL

Create a SQL Stored Procedure to return the desired data, using the xmlnamespaces and for xml path.  You will need to decide when you create your stored procedure whether it will be returning a single Order or a batch of Orders, there will be not difference to the XML generated in the stored procedure just a difference in how you select the records to return.  The stored procedure that I have created returns up to 5 Orders per call.

(complete SQL Stored Procedure available in download below)

image

Grant the BizTalk Application User group access to the AdventureWorks database and execute privileges to the GetSalesOrdersToProcess stored procedure.

Execute the stored procedure to create a sample XML document and save it to order.xml

In Visual Studio

Create a BizTalk Project (I am using Demo.WCFSQL.Polling for the solution name and AdventureWorks.Schemas for the project name)

In the BizTalk project add a generated item and select generated schema, in the generated schema dialog select Well-Formed XML, then select the order.xml file saved above.  This will create an order.xsd in your BizTalk project.  You may also need to update any numeric fields to the correct data types, the generated schema wizard sets number to the smallest data type that fits the sample data.

image

If you decide when creating your stored procedure to return multiple orders per execution, you will need to create and orders.xsd envelope schema, like this:

image

And set the Body XPath to the root node Orders.

Strong name your BizTalk project and set the deployment application name (I am using Demo.WCFSQL.Polling)

This is the complete Solution

image

Build and deploy your solution.

In BizTalk Administration Console

Expand the application that you deployed your solution into (I am using Demo.WCFSQL.Polling)

image

 

Create Receive Port and Receive Location

You now need to create the one-way WCF-SQL receive port and receive location (I am using AdventureWorks.Orders.Polling as the receive port name and AdventureWorks.Orders.Polling.WCFSQL as the receive location name)

SNAGHTML13f2d2e

The receive location can either be created as a WCF-Custom with the sqlBinding or as a WCF-SQL adapter (I am using the WCF-Custom with the sqlBinding)

SNAGHTML140cd14

After selecting WCF-Custom, click Configure.

On the General Tab type in the Address (URI), this consist of the protocol, server name, database name and Inbound Id like below:

mssql://<servername>//<databasename>?InboundId=Orders (my example looks like: mssql://.//AdventureWorks?InboundId=Orders)

SNAGHTML1444520

On the Binding Tab, select sqlBinding in the Binding Type drop down list

SNAGHTML146fad8

Set the following setting

Key Value Comment
inboundOperationType XmlPolling  
polledDataAvailableStatement select count(*) from [Sales].[SalesOrderHeader] where [status] = 5 This would be specific to your situation, this statement queries your table to see if any records are available to retrieve
pollingIntervalInSeconds 30 how often to try to retrieve data
pollingStatement exec [dbo].[GetSalesOrdersToProcess] this calls the stored procedure to retrieve data
xmlStoredProcedureRootNodeName Orders this is only necessary if you chose to bring back more than one order per execution
xmlStoredProcedureRootNodeNamespace http://AdventureWorks.Schemas.Orders this is only necessary if you chose to bring back more than one order per execution

Note: useAmbientTransaction defaults to True, if MSDTC is not configured between BizTalk and the source SQL Server you will have to set this to false

Click Ok, to close the WCF-Custom Transport Properties dialog

Select the appropriate Receive handler and set the Receive Pipeline to XMLReceive, then click OK to close the Receive Location Properties

 

Create Send Port

For this example we are just going to send the XML message directly out to a file location

You now need to create a one-way send port (I am using AdventureWorks.Orders.Send.FILE for the send port name)

SNAGHTML15574d8

Select a file location for the output XML messages (I am using C:\Working\Demo.WCFSQL.Polling\Out\%MessageID%.xml)

On the Filters tab, set the following filter: (this is for my example, yours may differ)

BTS.ReceivePortName == AdventureWorks.Orders.Polling

SNAGHTML157e65f

Click Ok to close the Send Port Properties dialog

 

Start the application

Right click on the Application and select start

image

 

Check the Output directory

You will notice with my example, 5 files are create at a each polling interval in the directory and that each file represents an order.

SNAGHTML163bd0e

Note: there are over 31,000 orders in the AdventureWorks database.

 

Summary

I hope this example give you the information that you need to get started with XmlPolling with BizTalk and the WCF-SQL Adapter.

 

Code for this Sample

 

Bill Chesnut, Principal Consultant, Mexia

 

 

Posted in Uncategorized | No Comments »

Disabling “Just My Code” Debugging in Visual Studio 2010

Sometimes you may be trying to step through code using the VS debugger, and run into a method with the [DebuggerStepThrough] attribute set:

image

You will then notice that any breakpoints will not be hit. Hovering over the hollow breakpoint icon will reveal this message:

“Breakpoints cannot be set in method or class with the ‘DebuggerStepThrough’ attribute when the debugger option ‘Just My Code’ is Enabled”

So you decide to temporarily disable the “Just My Code” option – only you may not be sure where it is. This may vary across different versions of Visual Studio, but in VS 2010 you will find it in Tools –> Options… and then selecting the Debugging –> General menu item on the left:

image

Un-ticking the “Enable Just My Code (Managed only) option will solve your problem; you’re breakpoints will now active.

HTH,

Dan

Posted in Uncategorized | No Comments »

GACUTIL Failure Due to Explorer Blocking Administrative Permissions

Recently, I encountered this perplexing error when building a solution in Visual Studio 2010:

Failure adding assembly to the cache: Administrator permissions are needed to use the selected options. Use an administrator command prompt to complete these tasks.

Several projects in the solution used a post-build event to install the assemblies in the GAC. However, I was logged into the machine with an administrator account and also running VS as Administrator – so why the authorisation issues?

After much contemplation [and the extraction of several hair follicles from my cranium], I finally arrived at the answer: I had an open instance of Windows Explorer running as Administrator (I had previously launched this with elevated privileges in order to delete some sticky files). Apparently this instance interfered with the gacutil permissions.

Once I closed the the Explorer instance, everything worked fine.

Dan

Posted in Uncategorized | No Comments »