BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in .NET XML, System.XML

 
 
Page 3253 of 17425

Reading Messages for Validation

Blogger : BizTalk Blogs
All posts : All posts by BizTalk Blogs
Category : .NET XML, System.XML
Blogged date : 2008 Jan 24

How do I perform XML validation against an entire message? There is a method to read the body of the message but it's only possible to read headers one at a time.

Although it sounds more complicated than it really is, a straightforward way to read an entire message is to write it instead. With the Message interface, you have more flexibility when writing a message to an XmlWriter than when reading from a generated XmlReader. Exchanging the roles of readers and writers is a common trick used in XML processing.

Here's a really short example of using an XmlWriter with some seekable storage. I've replaced the validation step with dumping out the contents of the message.

Message message = Message.CreateMessage(MessageVersion.Soap12WSAddressing10, "action!", "body");
MemoryStream stream = new MemoryStream();
using (message)
{
   using (XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8, false)) {
      writer.WriteStartDocument();
      message.WriteMessage(writer);
      writer.WriteEndDocument();
   }
}
stream.Seek(0L, SeekOrigin.Begin);
Console.WriteLine(new StreamReader(stream).ReadToEnd());

Obviously I'm leaving out more details here than just the validation step. For example, you'd probably want to harvest the original message for things like the message version and message properties so that you could reconstruct the message on the other side, rather than just throwing everything away.

Next time: Importing and Exporting WSDL Annotations


Read comments or post a reply to : Reading Messages for Validation
Page 3253 of 17425

Newest posts
 

    Email TopXML