Blog Stats
  • Posts - 27
  • Articles - 2
  • Comments - 49
  • Trackbacks - 8

 

BizTalk 2004 - Calculate message size

At this moment, I am working on a project for realization of integration with an external message hub, using BizTalk 2004 on our side. The external message hub is using EDI-like standards for message content that have been elevated to XML.

One of the rules is that the exact message size (in bytes) has to be specified for each message we send to this hub. Note that the message size has to be specified as a tag value in the message itself!

This problem challenged me, because the calculation to do this has a few interesting aspects. I remember having worked on comparable problems when developing compilers, back at the university. Furthermore, I am wondering how other users of this message hub have solved it in their systems.

In BizTalk 2004, I approached it as follows:

  • In the definition of the outbound XML-message, I promoted the tag that will hold the message size. This makes it possible to access (read and write) the value of the tag (by accessing the promoted property) outside a map.
  • A plain orchestration prepares the outbound message using a transform shape (map) in a construct shape
  • After the transform shape, in the same construct shape, I placed a message assignment shape
  • Because we are still inside the construct shape, we don't need to worry about message construction and related issues. The XLANG/s expression “only“ has to change the value to the promoted “message size“ property.

Now, back to reality. It all looks simple so far, but here is some complexity:

  • An XML-message travels through an orchestration without XML declaration and processing instructions (i.e. without the “bracket-question mark“ tags). The declaration and the processing instructions are added by the send pipeline attached to the send port. It is hard to predict what the size of the declaration tag will be, therefore, I decided to add a custom send pipeline to my orchestration, with the “Add XML declaration“ property set to false. No XML-declaration will be in the message that leaves the orchestration.
  • Forget about calculating the message size in an XLANG/s expression. This script language simply does not have the constructs for that.
  • Therefore, I created a C# (class lib) project, with an empty creator and a method for calculating the size. This is very powerful. I coded the size calculation functionality in this method, using the Math.log10 ad Math.floor standard functions
  • I built the project and took care that the dll was published to the GAC. Note that the class should be serializable, to avoid problems during BizTalk project buidling
  • From the original BizTalk project, I referred to the class library. As of that moment, my own method was available in the XLANG/s expression builder. Here, I only had to use a few statements to prepare and to call my own class, and to store the calculation results in the message.

The results so far are very good. The bespoke functionality calculates the exact message size and stores it in the message. The calculated size is equal to the number of characters reported by text editors (Notepad++) when I open the generated message file. When I check the message file properties in Windows Explorer, the file size is always 3 characters bigger than what I calculated. Apparently, this difference also exists between Notepad++ and Windows Explorer. I won't worry about that until we see test results.

The orchestration:

 

The XLANG/s expression (some names have been obscured for business reasons). The construct-shape constructs a message called ResltMsg. XmlMsg is a variable (type MsgInstance, defined by my own class), as well as XmlMsgSize (System.Decimal):

 

The C# code:

 

And the C# statement doing the actual calculation:

TotalSize = InitSize + (int)(Math.Floor(Math.Log10(InitSize + (int)(Math.Floor(Math.Log10(InitSize))))));

 

Please let me know what you think,

= Erwin


Feedback

No comments posted yet.


Post a comment





 

 

 

 

Copyright © Erwin Homan