Geeks With Blogs

Charles Young
Anthony Pounder asked me if you can do conditional compilation in Biztalk orchestrations.   The answer is yes, but you have to edit the XLANG/s in the .odx file directly.   This is not functionality that is surfaced in the orchestration designer.  
I wrote an article on XLANG/s a long time ago when I was still fairly new to BizTalk, and at the time I thought it would probably be a useful technique to be able to edit XLANG/s textually.   It turns out that almost all the XLANG/s functionality is surfaced in the orchestration designer.   This is one feature which isn't.   BizTalk orchestration currently provides two DSLs (Domain Specific Languages) layered on top of each other.   One is the graphical orchestration designer which creates ODX (Orchestration Designer XML), and the other is the XLANG/s language.   A long time ago (2001) Microsoft gave some consideration to making XLANG/s into a 'first-class' .NET language.   However, this never happened.  Instead, the worth of XLANG/s has been largely removed by the graphical orchestration designer (which did not exist in 2001).  There is almost no 'abstraction space' between the two DSLs - i.e., they are almost identical in what they do and the abstractions they offer.   By definition, the worth of a DSL is in terms of the abstraction space between it and the next layer down (generated C# in this case).   So, for BizTalk, one of the two DSLs is almost wholly redundant.   In this case, the obvious candidate for redundancy is XLANG/s, and sure enough, we do not expect it to survive into the planned 2008 'nextgen' version of BizTalk which will use Windows Workflow Foundation.
In the meantime, there are a couple of features which XLANG uniquely offers, and conditional compilation is one of them.   To use it, you need to edit the .odx file directly in a text editor.   The XLANG/s module contained in this file uses conditional compilation to include the ODX XML in the .odx file.   Note how inconsistent the use of the .odx extension is.  This is really an XLANG/s file that contains ODX, and not the other way around!   You can use #define to define a conditional constant, and then use #if just like C# to conditionally compile sections of the XLANG/s.  However, once you have created your constant, always enter #if and #endif in the expression editor in BizTalk, rather than directly in your .odx file.    The code you see in the expression editor is sourced from the ODX XML created by the designer and expression editior, rather than directly from the XLANG/s, so if you amend the XLANG/s directly, you can't see you changes in the designer, unless you find the corresponding XML content, and amend that to be identical. This is one of the main reasons why I cannot recommend editing XLANG/s directly.
If you are determined to do this, I would strongly recommend that you don't try to use conditional compilation except in expression and message assignment code.   I have experimented a bit, and this does work, but there is no way to reflect this in the ODX, and therefore you loose sight entirely of this in the orchestration designer.   Apart from anything else, this would be a reckless thing to do in terms of code maintenance.
Personally, I avoid doing this kind of thing at all.   As far as possible, I try to move the bulk of expression code out into helper classes.   If you do that, you can use conditional compilation to your heart's content.   Otherwise, I would use runtime branching if necessary.   It's not as neat or efficient, but at least you are not 'bending' the product.
The XLANG/s feature I really miss not having in the designer is the 'using' import directive.   XLANG/s supports this, but the designer does not, which means that, unless you are prepared to edit the .odx directly, you have to always use fully qualified type names in your expressions.   Yuk!
Previously posted at Posted on Friday, August 18, 2006 4:22 PM | Back to top

Comments on this post: BizTalk: Conditional Compilation in Orchestrations

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Charles Young | Powered by: