Friday, July 16, 2010

Isolated Host Instance Active Messages

Sometimes it has happened that our BizTalk 2006 R2 development and test servers end up with many active instances running on the Isolated Host Instance.

We can't terminate these instances using the administration console.

I found this solution on the web, using a database stored procedure (bts_CleanupMsgBox) that needs to be created first using a DB Schema file that's installed with BizTalk Server.

Don't forget to run this SP using "exec bts_CleanupMsgBox" instead of the "Execute" command from SQL Server Management Studio!!

PS: Always backup you databases before running bts_CleanupMsgBox!

Tuesday, April 20, 2010

XSLT in Any situation

XSLT: The Basics

Here are some basics XSLT commands that will be useful for the next step.

Setting a variable

Variables can only be set once. For loops consider recursive functions (a.k.a. templates).
<xsl:variable name="MyVariable">5</xsl:variable>

Reading a variable

<xsl:value-of select="@MyVariable" />

Read element

Read an element called Element from a node Node2 inside a node Node1
<xsl:value-of select="/Root/Node1/Node2/Element" />
Remember to close the tag

Setting a variable with the value of an element

<xsl:variable name="ValueOfElement">
<xsl:value-of select="/Root/Node1/Node2/Element" />

Read attribute

Read an attribute called Attribute from a node Node4 inside a node Node3
<xsl:value-of select="/Root/Node3/Node4/@Attribute" />

Setting a variable with the value of an attribute

<xsl:variable name="ValueOfAttribute">
<xsl:value-of select="/Root/Node3/Node4/@Attribute" />

If condition

Remember that XSLT is used to construct a XML document so the return of a value is not mandatory. The easiest way to think of it is like a print command, not like a function.
if(MyVariable>10) print MyVariable (> is a reserved char so we use &gt; instead)
<xsl:if test="@MyVariable &gt; 10">
<xsl:value-of select="@MyVariable" />

When the comparition is not against variables or numbers (string comparition for instance) the method is very similar, just delimit the string with ' '.
if(MyVariable="test") print "this is a test"
<xsl:if test="@MyVariable='10'">
this is a test

If, Elseif, Else

Does not exist an equivalent approach. We use a kind of switch instead.

if(MyVariable=10) print 1;
else if (MyVariable=10) print 10;
else print 100;

<xsl:when test="@MyVariable &lt; 10">1</xsl:when> <!-- if --!>
<xsl:when test="@MyVariable = 10">10</xsl:when> <!-- else if --!>
<xsl:otherwise>100</xsl:otherwise> <!-- else --!>

<Any> and <AnyAttribute>

A schema can be created without knowing the name of fields to fill. The menu Add Element has the option <Any>, and the same applies for Add Attribute (<AnyAttribute>). Like this, you can add virtually any node or attribute even after compilation. Be sure to define 0 at minimum occurrencies or it will fail while you don't have values to fill.

How to Map to <Any>

Create a Script Functoid of type "Inline XSLT". On the code area write the new tag and the desired value.


<xsl:value-of select="@MyVariable" />

<xsl:when test="@MyVariable='X'">1</xsl:when>

To give a namespace instead of writing directly the element, write the tag element:
<xsl:element name="ns2:ElementName">

and so on...

How to Map to <AnyAttribute>

Create a Script Functoid of type "Inline XSLT". On the code area write the new tag and the desired value between xsl:attribute tags.

<xsl:attribute name="NewAttribute">
<xsl:value-of select="$MyVariable" />

or any other case.

The Scripting Fuctoid is not linked to source schema, but be careful on linking Scripting Functoid to the destination schema. Point to the desired parent node.

Thursday, January 14, 2010

Pipelines in Biztalk

Creating pipelines in ports: knowing when to use PassThru Pipelines, XML Pipelines, and when to use Custom Pipelines.

A PassThru pipeline is straightforward. On a ReceiveLocation it receives a file without further treatment, validation or field promotion. The clear text message can be captured by a Send Port with filter by Receive Port.

A XML Pipeline is more complex. It analyses the received file and determines its structure. Properties are promoted and therefore more kinds of filters become available (specially the useful namespace).

In a XML pipeline there are no limitations. The schemas can by converted, envelopes can be splitted, all options are available under the properties section. To avoid time-consuming configurations in that area – and reduce error-proneness – a Custom Pipeline should be made. It stores the configuration inside the DLL and thus can be reused in another port, or even exported to another environment without dues.

The same logic applies to SendPipelines. Usually a PassThruTransmit is enough because the message is already known in Biztalk. If a format change is needed (to Flat File i.e.) an XMLTransmit with the adequate assembler is the only option. And to place that configuration at development level, a Custom Pipeline.

Hint: For the Flat File Assembler there is no need to select a schema. According to this MSDN page If no schema is specified, run-time schema discovery is done. It was tested and confirmed. It makes development a lot easier:
  • by reducing the number of pipelines. There's no need for multiple assembler pipelines. Instead of one pipeline for each schema, a single pipeline can be used by the entire application.
  • by making them faster to upgrade. When refering schemas from external DLL's, the assembly version is required. In the past if that DLL was changed (it happens in our dev environment on a weekly basis) we had to manually correct each map and pipeline. Now the pipelines are not a problem.