For some work I was doing with BizTalk 2006, I had used reflection and played around with internals of BizTalk Assembly. With BizTalk 2006 R2 now available, I decided to give the code I was working then, a try again.
I have earlier blogged about installing BizTalk 2006 R2 on my Vista machine and as part of that I had built the CallOrchestartion SDK Sample. I decided to work with this sample code itself.
Before going ahead, a word of caution: The internals of BizTalk Assembly aren't published and are subject to change. Hence any code (like below) that you write assuming the internals, may break with future versions.
Let's see how we can load a BizTalk Assembly and find out if it contains an Orchestration or not. For this, we write the regular reflection code as below
Assembly al = Assembly.LoadFile(@"C:\Program Files\Microsoft BizTalk Server 2006\SDK\Samples\Orchestrations\CallOrchestration\bin\Development\CallOrchestration.dll");
BizTalk Orchestartions derive from BTXService base class. So we search for it as below
Type orc = null;
BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static ;
Type types = al.GetTypes();
foreach (Type t in types)
if (t.BaseType.Name == "BTXService")
orc = t; //t.FullName will give the name of the orchestration
if (orc == null)
//no orchestartion. act accordinly
Assuming we get the Orchestration, there are two key fields in the orchestration that contain all the information about it. There is a field called _symInfo that contains information about all the shapes (including children) and the messages used in the orchestartion. There is another field called _symODXML, which contains all the relevant properties for the shapes in the orchestration. Both of these are XML content and you can load and parse them using XML DOM APIs. To load them, something like following will work
FieldInfo info = orc.GetField("_symInfo", flags);
string syminfoString = info.GetRawConstantValue().ToString();
FieldInfo odXML = orc.GetField("_symODXML", flags);
string odxmlString = odXML.GetRawConstantValue().ToString();
Note that the odXML content uses a namespace - "xmlns:om='http://schemas.microsoft.com/BizTalk/2003/DesignerData'" and hence when working with the XML, you will need to add the appropriate namespace before firing any XPATH queries.
XmlNamespaceManager namespMgr = new XmlNamespaceManager(doc.NameTable);
(where doc is the XmlDocument object).
As important feature of BizTalk that will help understand the XML structure better and get to see the source code of BizTalk Ochestration is the ability to generate the C# files. Refer to this blog for more details on it.