Sometimes we want to bypass the adapters and perform the communication thru .NET code. Sometimes we want to access multiple values, or recursive values, of a message inside a helper class that supports an orchestration. Sometimes we want to perform a complex transformation or construct a message thru .NET code instead of a BizTalk Server map.
And for each of these circumstances, we can have several approaches, one that is simple, effective, and transversal to all of them is to use the XML Schema to generate a .NET class. This way, you have a quick and straightforward way to represent the messages you get from your BizTalk processes into a .NET class.
The easy way to generate classes that conform to a specific schema is to use the need to use the XML Schema Definition tool (Xsd.exe). You can do that by:
- Open a Developer Command Prompt for VS <edition>
- On the command prompt, navigate to the Schema folder and type
- xsd /classes /language:CS Schema1.xsd
For complex schemas that import or include other schemas you need to provide all the dependencies, for example:
- xsd /classes /language:CS Schema1.xsd Schema2.xsd
Now you will be able to import the C# class generated by the tool to your helper project and the rest is simple!
On the Orchestration you can create a variable that represents that class:
- On property Type select <.NET Class…> and select the class that you created previously
- From the Browse and Select .Net Type to reference, you need to select the proper assembly and the Type.
Then by using C# code inside Message Assign or Expression Shape you can serialize or deserialize XML document into C# and vice versa in a simple and straightforward way
//CONVERT MESSAGE INTO C# OBJECT varPersonMsg = msgInput; //CONVERT C# OBJECT INTO BIZTALK MESSAGE msgOutput4 = varPersonMsg;
or if we have a function in a helper class like:
public static XmlDocument MapPersons(Person person) { ... }
we can directly pass the message to the function without the need to create a variable:
msgOutput4 = Support.Mapping.MapPersons(msgInput);