Wednesday, October 30, 2013

Poor-man's scheduled trigger message task in BizTalk

From time to time you might encounter the need for a trigger message in BizTalk. No matter the reason, you need a message that is sent to BizTalk every x minutes that in turn will trigger a process.

In most cases, you will end up installing the BizTalk Scheduled Task Adapter from Codeplex. This adapter is throughly tested and well-used in different scenarious around the world and is a very valid option.

If you do not want to install a third-party adapter for any reason but still need a trigger message to be sent every x minutes, you can script it using the Windows Task Scheduler. This solution will however require you to add the scheduled task to your monitoring solution to make sure that it stays active.

Yet another solution that can be commonly seen is to have an SQL Agent job set a flag in a table every x minutes and then have BizTalk poll this table according to the usual techniques.

My solution to creating a simple trigger message is to utilize the built-in features in BizTalk and not depend on any external trigger mechanism. By setting up a simple receive location with the WCF-SQL adapter, it can be made.

First, create a receive port and location. In the WCF-SQL transport properties, set the endpoint URI to any valid SQL server. I use BizTalks management database in this case, since there won't be any load on it at all from this receive location and it always will be available.

Next, in the Binding section, set the XmlStoreProcedureRootNodeName to TriggerRoot and the XmlStoredProcedureRootNodeNamespace to http://trigger/v1

Using XmlPolling as InboundOperationType, you set the PolledDataAvailableStatement to Select 1 to simply always trigger a polling statement execution. The PollingStatement in turn is set to WITH XMLNAMESPACES(DEFAULT 'http://trigger/v1') select CURRENT_TIMESTAMP for xml raw ('Trigger'), ELEMENTS

PollingIntervalInSeconds can be set to any interval you like. Also make sure that the PollWhileDataFound property is set to False.

What this does is that when the receive location is started, the first statement will return 1, telling BizTalk that there is a message to be fetched and to execute the polling statement. This statement will return a raw xml message that will look like this:

<TriggerRoot xmlns="http://trigger/v1">

You can then create a schema for this message and then in turn use it in your BizTalk solution to trigger a process on a timely schedule. Quick and simple and does the job. The bonus is that as long as the receive location is up and running, you know that it will create a message for you.


  1. Excellent, just what I needed.

  2. There was a failure executing the receive pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "XML disassembler" Receive Port: "LastUpdateRunTime" URI: "mssql://pdw6zsqlext/dvlp/aztscdvlp?InboundId=Trigger" Reason: Finding the document specification by message type "" failed. Verify the schema deployed properly.

    1. Hi!
      You seem to have set the InboundOperationType in the adapter properties to "Polling" instead of "XmlPolling".