Two simple Message Utilities

Link. January 3, 2006. Comments [0]. Posted in: BizTalk
Two fairly common operations in BizTalk Server 2004/6 are creating new messages from XML literal strings, as well as getting the XML text out of an existing BizTalk message in an orchestration.

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


Comments are closed.

Syndicate

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...

tomasrestrepo @ twitter My Flickr photostream My saved links on delicious My Technorati Profile

email: tomas@winterdom.com
msn: tomasr@passport.com

View my profile on LinkedIn

MVP logo

Ads


Categories

Statistics

Total Posts: 1050
This Year: 1
This Month: 1
This Week: 0
Comments: 826

Archive

Other

Copyright © 2002-2008, Tomas Restrepo.

Powered by: newtelligence dasBlog 2.2.8279.16125

Sign In