Microsoft.BizTalk.TypeSystem
BtsAssemblyManagerClass manager= new BtsAssemblyManagerClass(); CurrentBtsAssembly=(Microsoft.BizTalk.MetaDataOM.IBizTalkAssembly)manager.Add(path); |
The BtsAssemblyManager’s class is located in the BtsMetaDataOM assembly. Following the line of my post talking about reflection I want to show some code about how to deal with BizTalk elements. The next code shows how to iterate over the list of orchestration contained in the assembly.
IEnumerator OrchestrationList= CurrentBtsAssembly.Orchestrations; while(OrchestrationList.MoveNext()) { Microsoft.BizTalk.MetaDataOM.IBizTalkOrchestration CurrentOrchestration= (Microsoft.BizTalk.MetaDataOM.IBizTalkOrchestration)OrchestrationList.Current; Console.WriteLine(CurrentOrchestration.Name); } |
The code showed can be used to deal with other BizTalk elements like: MessageTypes, PipeLines, etc.
A similar example shows the same operation but iterating over the Schemas collection and printing the schema’s code.
IEnumerator SchemaList= CurrentBtsAssembly.Schemas; while(SchemaList.MoveNext()) {Microsoft.BizTalk.MetaDataOM.IBizTalkSchema CurrentSchema= (Microsoft.BizTalk.MetaDataOM.IBizTalkSchema)SchemaList.Current; Console.WriteLine(CurrentSchema.Name); Console.WriteLine(CurrentSchema.XmlContent); } |
Using this assembly we can obtain almost all the information of the BizTalk elements present in an assembly. The following function iterates over the Operations of a PortType and prints the name and communication pattern of each one.
public void OperationTest(Microsoft.BizTalk.MetaDataOM.IBizTalkPortType TargetPortType) { IEnumerator OperationList= TargetPortType.Operations; string msg= ""; while(OperationList.MoveNext()) { Microsoft.BizTalk.MetaDataOM.IBizTalkOperation CurrentOperation= (Microsoft.BizTalk.MetaDataOM.IBizTalkOperation)OperationList.Current; Console.WriteLine(CurrentOperation.Name); if(CurrentOperation.IsOneWay) Console.WriteLine("Communication Pattern: Oneway"); else Console.WriteLine("Communication Pattern: RequestResponse"); } } |
We can mix the functionality of the TypeSystem assembly with other BizTalk-based assemblies to develop more complex applications. In the example below we use the TypeSystem and Microsoft.XLANGs.BaseTypes assemblies to obtain the Xml Schema of each Xsd part of the MesageTypes in an assembly.
public void MessageTypeTest() { IEnumerator MsgTypeList= CurrentBtsAssembly.MessageTypes; while(MsgTypeList.MoveNext()) { Microsoft.BizTalk.MetaDataOM.IBizTalkMessageType CurrentMsgType= (Microsoft.BizTalk.MetaDataOM.IBizTalkMessageType)MsgTypeList.Current; if(CurrentMsgType != null) { Console.WriteLine(CurrentMsgType.Name); Console.WriteLine(CurrentMsgType.XmlContent); IEnumerator MsgPartList= CurrentMsgType.Parts; while(MsgPartList.MoveNext()) { Microsoft.BizTalk.MetaDataOM.IBizTalkMessagePart CurrentMsgPart= (Microsoft.BizTalk.MetaDataOM.IBizTalkMessagePart)MsgPartList.Current; if(CurrentMsgPart.Category == Microsoft.BizTalk.MetaDataOM.MessagePartCategory.eMPSchemaRoot) MesagePartTest(CurrentMsgPart); } } } }
public void MesagePartTest(Microsoft.BizTalk.MetaDataOM.IBizTalkMessagePart targetpart) { /* CurrentNetAssembly is an instance of System.Refelction.Assembly that represents the compiled BziTalk assembly.*/
Console.WriteLine(targetpart.Name); string PartTypeName= targetpart.WrapperType; Type PartType= CurrentNetAssembly.GetType(PartTypeName); MethodInfo info= PartType.GetMethod("get_PartSchema"); SchemaBase PartSchema= (SchemaBase)info.Invoke(null, null); XmlSchemaCollection SchemaList= PartSchema.SchemaCollection; foreach(XmlSchema sch in SchemaList) { MemoryStream mstr= new MemoryStream(); sch.Write(mstr); mstr.Position= 0; Byte[] buffer= mstr.GetBuffer(); PrintBuffer(buffer); } } |
In BizTalk Server 2004 exists three fundamental types of messages: MultiPart, Xsd and DotNet. The Xsd and DotNet messages are MultiPart messages with a single part. The type of each part of a MessageType can be an Xsd schema, a .NET type or another multipart MessageType. The Category property of a MessagePart indicates the type of the part. In the MesagePartTest method we first obtain the Part’s WrapperType that is the type’s name of the part in the compiled assembly. Next we obtain the Part’s type and invoke the get_PartSchema method that returns a SchemaBase instance. And finally we print each schema presents in the SchemaBase object. I hope that you have enjoyed the examples in this post. I will continue talking of Microsoft.BizTalk.TypeSystem assembly in next posts.