Jon Flanders' Blog

Passing binary data to BizTalk

Friday, April 15, 2005 7:36:41 AM (GMT Daylight Time, UTC+01:00)

Aaron had a post tonight about XML messaging in BizTalk. I think one of the biggest misconceptions out there about BizTalk is that is has to use XML messages. Although BizTalk has a strong preference for XML messaging, it isn't built to only accept XML.

The key to all subscriptions in BizTalk is promoted properties in the Message Context. The Message Context is a set of name/value pairs that travels along with each Message as the Message goes from one BizTalk Service to another. Promoted properties are special (different than just regular context properties) in that they can be used as subscriptions - where a Service can subscribe to messages based upon certainly named properties (like ReceivePortName for example). MessageType is one of the most typically used promoted properties for subscriptions, in fact almost every Orchestration uses MessageType as part of its subscription (usually an Orchestration uses MessageType and the ReceivePortID - the GUID that uniquely identifies a Receive Port as its two pieces of subscription information - the MessageType coming from the PortType used in the Orchestration and the ReceivePortID coming when you bind the Orchestration at configuration time).

 

Actually BizTalk will accept just about any actual physical message format. The key concept is to make sure that whatever the message format, that the subscriptions you set up actually work. Generally getting the subscription to work properly is just a matter of understanding how the pieces fit together.

 

You can download this sample if you are interesting in seeing how BizTalk will allow you to send even messages which are totally binary (in this case, .NET types that have been serialized using the .NET BinaryFormatter). In this sample, I have an Orchestration that takes in a Message of a particular type, which happens to be a .NET message type. Typically when you use a .NET message type in an Orchestration, the Messaging Engine expects that you will send an Xml representation of that object (as if the object had been serialized using the XmlSerializer type). But if the .NET type uses the Microsoft.XLANGs.BaseTypes.CustomFormatterAttribute you can specify an implementation of IFormatter (the .NET Serialization interface) and then pass a .NET as a non-XML serialized message. The key to making this work of course is the key to making any subscription in BizTalk work, which is to make sure the correct Context Properties have been promoted (the key Context Property of course is MessageType). The Orchestration not only accepts a message of this type but also deserializes (implicitly through a cast which the BizTalk Orchestration compiler turns into code that runs the BinaryFormatter) the message into a live .NET object, and the serializes that new object into a Binary message to send to its Send Port - back into the MessageBox.

In order for this sample to work (and any messaging to an Orchestration which doesn't use the typical message routing), there is a custom pipeline in the "BinFormat" project that puts the MessageType into the message context as a promoted property. In this case the MessageType is the fully-qualified type name of the .NET message type, in the typical case the MessageType is the Namespace URI of the schema the message is associated with the Root element name of the document tacked onto that string with the hash symbol (like http://mynamespace#RootElementName). This custom pipeline uses my ContextAdder component - which you can download here.

The whole point here is that BizTalk does not *have* to rely on XML to get its work done, although using XML in BizTalk is generally the preferable solution. Also there is a btsnapshot directory (binapp) inside of the solution folder you can use with BTSnapshot if you just want to setup the ports and see the app run. The SaveLoadBinaryMessage application can be used to write a formatted message to the file system, and also so deserialize a message written to the Send Port (assumes you are using the FILE adapter with the BinOrch Orchestration). You can download the sample (full source) here (259.92 KB). Happy Binary BizTalk messaging.

BizTalk   #    Comments [0]   Tracked by:
http://www.traceofthought.net/PermaLink,guid,c5418f3d-2ea7-4530-ab9c-ae4c49154fc... [Pingback]