« Clemens, ES and JITA | Main | Turning Batch into on-line »
The first option is very useful when creating new messages from scratch. However, the method I show here is not very useful for complex messages, because it would be very hard to maintain an read. For those scenarios, I really recommend Scott Colestock's option of creating messages from embedded resources in .NET assemblies; it's a much better option.
Here's some very small, yet useful piece of code to accomplish these tasks:
// // XmlHelper.cs // // Author: // Tomas Restrepo (tomasr@mvps.org) // using System; using System.IO; using System.Xml; using Microsoft.XLANGs.BaseTypes; using System; using System.IO; using System.Xml; using Microsoft.XLANGs.BaseTypes; namespace Winterdom.BizTalk.Util { /// <summary> /// Helper BizTalk class to deal with XML Based /// messages /// </summary> public class XmlHelper { /// <summary> /// Creates a typed BizTalk message /// out of a string containing valid XML. /// </summary> /// <remarks> /// This does not validate the message at all. /// </remarks> /// <param name="xml">XML content</param> /// <returns>The BizTalk Message</returns> public static XmlDocument CreateMessage(string xml) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); return doc; } /// <summary> /// Returns a string containing the XML from the message /// </summary> /// <param name="part">Message</param> /// <returns>The xml</returns> public static string GetMessageXml(XLANGPart part) { Stream s = (Stream)part.RetrieveAs(typeof(Stream)); using ( StreamReader reader = new StreamReader(s) ) { return reader.ReadToEnd(); } } } // class XmlHelper } // namespace Winterdom.BizTalk.Util
About
Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...
email: tomas@winterdom.com msn: tomasr@passport.com
Syndicate
Ads
Links
Categories
Statistics
Blogroll
Post Archive
Other
Copyright © 2002-2008, Tomas Restrepo.
Powered by: newtelligence dasBlog 2.1.8102.813