Using xpath expressions in BizTalk

Xpath is a very nice way to retrieve values from BizTalk messages, especially when you can not use distinguished fields, for example in looping records. It can however be quite a complicated task as well, to find out how to retrieve a certain value. To that end, I have created a list of xpath filter expressions I commonly use. In these examples I will be using the following XML.

<root>
	<delivery>
		<deliverytype>Home</deliverytype>
		<boxinfo>
			<boxid>22</boxid>
		</boxinfo>
	</delivery>
	<delivery>
		<deliverytype>Work</deliverytype>
		<boxinfo>
			<boxid>35</boxid>
		</boxinfo>
	</delivery>
	<delivery>
		<deliverytype>Home</deliverytype>
		<boxinfo>
			<boxid>12</boxid>
			<boxid>87</boxid>
		</boxinfo>
	</delivery>
	<boxes>
		<box material="cardboard">
			<id>12</id>
			<contents>Envelopes</contents>
		</box>
		<box material="cardboard">
			<id>22</id>
			<contents>Surface Pro 2</contents>
		</box>
		<box material="plastic">
			<id>35</id>
			<contents>Stickers</contents>
		</box>
		<box material="cardboard">
			<id>87</id>
			<contents>Stamps</contents>
		</box>
	</boxes>
</root>
  • Filter on index
    Get the third delivery node.

    /*[local-name()='Root']/*[local-name()='Delivery'][2]

    Get the deliverytype node of the second delivery.

    /*[local-name()='Root']/*[local-name()='Delivery'][2]/*[local-name()='DeliveryType']
  • Filter on subnode text
    Get all delivery nodes, which have a deliverytype of Home.

    /*[local-name()='Root']/*[local-name()='Delivery'][*[local-name()='DeliveryType'][text()='Home']]

    Get the deliverytype node of the delivery for BoxID 87.

    /*[local-name()='Root']/*[local-name()='Delivery'][*[local-name()='BoxInfo']/*[local-name()='BoxID'][text()='87']]/*[local-name()='DeliveryType']

    Get the deliverytype node, of the box which contains the stickers.

    /*[local-name()='Root']/*[local-name()='Delivery'][*[local-name()='BoxInfo']/*[local-name()='BoxID'][text()=/*[local-name()='Root']/*[local-name()='Boxes']/*[local-name()='Box'][*[local-name()='Contents'][text()='Stickers']]/*[local-name()='ID']]]/*[local-name()='DeliveryType']
  • Continue reading

Converting String to XLangMessage (Streaming)

Often when you want to create a message in an orchestration, the option of using an XMLDocument is chosen for this. However, this option can be a serious performance hit, as your entire message will be loaded into memory, and can become as large as 10 times it’s original size. To avoid these performance hits, I have created 2 small helper methods, which allow you to instead use BizTalk’s native messages instead of an XMLDocument, and create the message in a streaming way. Using these, you can simply create a message from a string (and the other way around).
Continue reading

Using XPath expression with filters in orchestration

In one of our projects, we hadto do an xpath expression in an orchestration to find a value from a nodes subnode, where another subnode has a specific value.
So our input is like this:

<Root>
	<Delivery>
		<DeliveryType>Home</DeliveryType>
		<BoxInfo>
		<BoxID>22</BoxID>
		</BoxInfo>
	</Delivery>
	<Delivery>
		<DeliveryType>Work</DeliveryType>
		<BoxInfo>
		<BoxID>35</BoxID>
		</BoxInfo>
	</Delivery>
	<Delivery>
		<DeliveryType>Home</DeliveryType>
		<BoxInfo>
		<BoxID>12</BoxID>
		<BoxID>87</BoxID>
		</BoxInfo>
	</Delivery>
	<Boxes>
		<Box>
			<ID>12</ID>
			<Contents>Envelopes</Contents>
		</Box>
		<Box>
			<ID>22</ID>
			<Contents>Surface Pro 2</Contents>
		</Box>
		<Box>
			<ID>35</ID>
			<Contents>Stickers</Contents>
		</Box>
		<Box>
			<ID>87</ID>
			<Contents>Stamps</Contents>
		</Box>
	</Boxes>
</Root>

Now what we wanted to do, is to have the ID’s of the boxes, where the delivery type was Home.
Continue reading

UBL in maps slowing down build

In my current project we are using UBL as our internal format. UBL, or Universal Business Language, is an effort to define a library of standard electronic XML business documents such as purchase orders and invoices. The plusside of using UBL is you have a industry standard, and there are various components and resources to easily integrate it in your solutions. The downside,from a BizTalk perspective is, the schema’s are very large, and have lot of schema references, which again have there own references, which can go up to 8 levels deep.
Continue reading

Service Bus for Windows Server – Posting messages for BizTalk

In my previous post I talked about how we are using Service Bus as our queueing mechanic, from which we read messages using BizTalk. When using Paulo Salvatori’s test client we could read these messages in BizTalk, however when we were publishing messages from our own .NET applications, we weren’t able to receive them in BizTalk. These were the errors we got in the event log:

The adapter “WCF-Custom” raised an error message. Details “System.ServiceModel.CommunicationException: Unrecognized message version.

The adapter “WCF-Custom” raised an error message. Details “System.FormatException: Input string was not in a correct format.

Error
After some research, I found out this is due to the way the messages are being deserialized by the BizTalk WCF adapter. To solve this, when placing the messages on Service Bus, we have to publish them as WCF messages, instead of using the Service Bus SDK.
Continue reading

Using USB devices in Hyper-V

For a PoC I’m doing I need to connect a netduino to my machine. Since I like to keep my projects separated, I try to use virtual machines as much as possible. I work on a Windows 8 environment, so I have Hyper-V, and set up my VM’s in that. One of the downsides to Hyper-V is you can’t easily access USB devices you plug into your machine inside your VM. Since the netduino is a USB connected device, I have been doing some research, and found out we can use RemoteFX USB redirection for this. Continue reading

Missing tracking data

Over the last few days we had increasing problems with missing and incomplete tracking data. For some interfaces we would only see the incoming or outgoing data, for other interfaces no data was being shown at all.

Inspection of the DTA table in the database showed it was missing in the database as well, so we could rule out the administration console and its queries.

After some searching, I found out the tracking events on the pipelines had been unchecked. After re-enabling these everything worked normally again. Continue reading

WCF-SQL adapter, using MSDTC cross domain

Today I had to set up the WCF-SQL adapter, to write data to a database used for BI purposes. We have our BizTalk machine located at a hoster, the BI database is located on a server on-premise at the client, and a VPN connection connects the servers. The servers are in different domains.

Generating the schemas went without problems, however once we wanted to do some actual work on the database we got the following 2 errors in the event log:

MSDTC encountered an error (HR=0x80000171) while attempting to establish a secure connection with system BIBIZ.

And

The adapter failed to transmit message going to send port “Communicate with BI” with URL “mssql://bibiz.acme.nl//bibizDatabase?”. It will be retransmitted after the retry interval specified for this Send Port. Details:”System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed. —> System.Runtime.InteropServices.COMException: The MSDTC transaction manager was unable to push the transaction to the destination transaction manager due to communication problems. Possible causes are: a firewall is present and it doesn’t have an exception for the MSDTC process, the two machines cannot find each other by their NetBIOS names, or the support for network transactions is not enabled for one of the two transaction managers. (Exception from HRESULT: 0x8004D02A)

It turned out, that to use MSDTC across domains you have to set some options. I will list the actions to be taken here, both for my own reference, and to help anyone else running into this problem. Continue reading