Monday, January 23, 2006

Customizing the WSDL generated by the
‘BizTalk Webservice Publishing Wizard’

Exposing BizTalk interfaces as webservices is very easy using the ‘BizTalk Webservice Publishing Tool’. In almost all cases this tool generates a correct functioning web service which does not need any code modification.

However, there are situations where tweaking the code of the generated web service is necessary. Recently I needed two different BizTalk interfaces to expose the exact same WSDL. Because the two interfaces had different names for namespaces and artifacts, the generated webservices and WSDL were not the same.

You can solve this by using the SoapExtensionReflector. The BizTalk Webservice Publishing Wizard generates a class called ‘WsdlExtensions.cs’ for every webservice that is generated. By including this file in the generated VS.Net webservice project and adding the type in the 'soapExtensionReflectorTypes' section of the web.config (see header comments of
WsdlExtensions.cs), you’re able to control the generated WSDL for the webservice.

By default this file is generated with code for XML schema replacement in the WSDL, but you can use this to change other parts. For example, to override the SOAP service name, you can use:

public override void ReflectMethod()


    ProtocolReflector reflector = this.ReflectionContext;

    reflector.Service.Name = "MyNewServiceName";


After recompiling the web service the service name in the WSDL is changed to the new value.

Tuesday, January 10, 2006

Biztalk Host Manager 2004

Since Isaac is publishing post after post I thought it is time for me to also post something.

I developed a useful tool, called the Biztalk Host Manager (BTSHostManager), which we use in our development team to be able to quickly stop, start and especially restart BTS host instances.

Because all our developers found it a helpful tool we thought we would make it available for download.

Some features:
- It monitors background service state change of host instances (not by default, use options to enable) .
- It works for Biztalk 2004 and 2006.

- A seperate Biztalk 2006 version (compiled against 2.0 framework) will be available soon.
- This is not the final release version. We are still testing it, so please mail me any bugs you find.

Thursday, January 05, 2006

Mapping complex conditions in BizTalk with XSLT

Recently I found myself in a situation where I needed to evaluate a set of complex conditions that I could not use the Business Rules Engine for. The BizTalk mapper was able to achieve the conditionality by chaining a series of about 21 functoids together but this became very unmanageable especially since I was combining false statements to see if both were false, then returning a true to an “And” functoid (&) which evaluated another branch as true and passed a result to the node in the destination schema, you get the idea.

An easier way is to plug in XSLT. There are disadvantages to doing this, the main one being its maintainability and transparency but when faced with the daunting set of functoids described above, it looked a decent option.

The XSLT function that I used was the <xsl:choose> statement, inside the statement was a set of conditions which, if true, would return a value/values to the destination schema. In the last part of the statement was the <xsl:otherwise> condition which could set values if the conditions presented were not valid and you had a default you wanted to present in that event.

<xsl:variable name="var:vAnnuity" select="count(/*[local-name()='InternalSupport' and namespace-uri()='http://internal_support']/*[local-name()='LoanPartItems' and namespace-uri()='' and Method='Annuity'])" />

<xsl:variable name="var:vLinear" select="count(/*[local-name()='InternalSupport' and namespace-uri()='http://internal_support']/*[local-name()='LoanPartItems' and namespace-uri()='' and Method='Linear'])" />

<xsl:variable name="var:vTotalCount" select="count(/*[local-name()='InternalSupport' and namespace-uri()='http://internal_support']/*[local-name()='PartItems' and namespace-uri()=''])" />

<xsl:variable name="var:vHasValidEndowment" select="count(/*[local-name()='InternalSupport' and namespace-uri()='http://internal_support']/*[local-name()='LoanPartItems' and namespace-uri()='' and isValid ='true'])" />

<xsl:variable name="var:vHasValidId" select="count(/*[local-name()='InternalSupport' and namespace-uri()='http://internal_support']/*[local-name()='Ready' and HasValidId ='true'])" />

<xsl:element name="LeningSoort">


        <xsl:when test="$var:vAnnuity = $var:vTotalCount">

            <xsl:value-of select="1" />


        <xsl:when test="$var:vLinear = $var:vTotalCount">

            <xsl:value-of select="2" />


        <xsl:when test="($var:vHasValidEndowment = $var:vTotalCount) and ($var:vHasValidId = $var:vTotalCount)">

            <xsl:value-of select="3" />



            <xsl:value-of select="4" />




Of course each specific case requires different XSLT, but this should provide a framework of how to do this within a functoid.

To set up the XSLT:

• Create XSLT similar to the one above which meets your needs
• Drop a scripting functoid on your map
• Connect the output parameter to the node you want to create
• Note: do no include any input parameters, the XSLT is setup already to look them up
• Open the scripting functoid’s, click the (…) inside “Configure Functoid Script”
• Under “Script type” choose “Inline XSLT”
• Paste your XSLT snippet in the text box

Tuesday, January 03, 2006

Remove empty nodes in BizTalk by using XSLT

If you have ever had a map which begins to look unmanageable with tons of value mappings or extra functoids to simply manage empty nodes you don’t want in your output then you should consider using an XSLT mapping to clean the document up for you.

This involves actually making 2 mappings instead of one, but the upside is faster development with a nominal performance cost. Instead of adding functoids, testing and retesting the output, let the mapper generate the empty nodded and then add an extra mapping step with the following XSLT embedded in it:

<?xml version="1.0" ?>

<xsl:stylesheet xmlns:xsl="@@ YOUR NAMESPACE @@" version="1.0" xmlns:ns0="http://Stater.Isvcs.Iface.BO.GetLoanData.ElfV2">

    <xsl:output method="xml" indent="yes" />

    <xsl:template match="node()">

        <xsl:if test="count(descendant::text()[string-length(normalize-space(.))>0]|@*)">


                <xsl:apply-templates select="@*|node()" />




    <xsl:template match="@*">

        <xsl:copy />


    <xsl:template match="text()">

        <xsl:value-of select="normalize-space(.)" />



Save this snippet (or download it here) into your project (open the XSLT and change the namespace!) then create a new map. Make your source and destination schemas the same and in the map properties add your XSLT in the “Custom XSLT path” setting. Place the new map after the “dirty” map; the output should give you an XML document free of extra nodes and a map free of extra functoids.

Of course, if you are doing a strictly messaging based implementation then you are out of luck unless you chain ports together but within an orchestration using XSLT to remove empty nodes might work well for you.

Monday, January 02, 2006

Blogging about BizTalk? Then this is a
must have tool

I’ve found a tool recently that will make blogging about BizTalk easier. It’s been around for a while but if you are like me and have never heard of it before, CopySourceAsHtml is very useful.

If you have been in the situation of wanting to post a code or XSLT snippet onto your blog and found yourself writing HTML to make it look like it does in Visual Studio (or resort to screen shots) then fret no more, CopySourceAsHtml will take anything that you can open in VS (source code related) and convert it to HTML for you.

The tool is written by Colin Coller and can be downloaded on the CopySourceAsHtml homepage. In addition, Colin has a blog which updates progress on the tool. I read that a VS 2005 version is soon to be ready.

A couple of tips when using it:

  • After installing you should be able to open any C# source code page, highlight and right click a code snippet and see a new “Copy as HTML” item on the menu. But, if for example you want to copy XSLT, the item doesn’t show up. Use the edit menu instead.
  • When you copy something as HTML, under general, uncheck the “Number lines from:” box unless you really want them and also check the “Embed styles” box since blog tools/some browsers wont recognize the style sheet that gets created. Embeding the style makes it a simpler operation.