BloggingAbout.NET
Thoughts of developers
BizTalk: Create Message based on deployed schema

Here is technique for generating an instance of a BizTalk message (a.k.a, XmlDocument) based on a deployed schema.  It requires references to the following assemblies:

Assembly Location
Microsoft.BizTalk.Pipeline %Program Files%/Microsoft BizTalk Server
Microsoft.BizTalk.ExplorerOM %Program Files%/Microsoft BizTalk Server/Developer Tools

In a class library that has references to the above libraries, create a public class with the following two public methods:

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using Microsoft.BizTalk.Component.Interop;

using Microsoft.BizTalk.ExplorerOM;

 

namespace Spike.Sandbox

{

public class Utilities

{

/// <summary>

/// Build a BizTalk message for a single root node message

/// </summary>

/// <param name="schemaName"></param>

/// <returns></returns>

public static XmlDocument CreateBTSMessage(string schemaName)

{

return CreateMessage(schemaName, schemaName);

}

 

/// <summary>

/// Build a BizTalk Message for a multi-root node message

/// </summary>

/// <param name="schemaName"></param>

/// <param name="rootNode"></param>

/// <returns></returns>

public static XmlDocument CreateBTSMessage(string schemaName, string rootNode)

{

return CreateMessage(schemaName, string.Format("{0}+{1}", schemaName, rootNode));

}

These two methods call a private method that accesses the BizTalk management database to retrieve a deployed schema and construct the message:

private static XmlDocument CreateMessage(string schemaName, string rootNode)

{

XmlDocument doc = new XmlDocument();

DocumentSpec docSpec;

 

BtsCatalogExplorer catalog = new BtsCatalogExplorer();

catalog.ConnectionString = "Data Source=myServer;Initial Catalog=BizTalkMgmtDb2;Integrated Security=True";



Schema schema = catalog.Schemas[schemaName];



if (schema != null)

{

docSpec = new DocumentSpec(rootNode, schema.BtsAssembly.DisplayName);



if (docSpec != null)

{

StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

 

try

{

doc.Load(docSpec.CreateXmlInstance(sw));

}

finally

{

sw.Dispose();

}

}

}

 

return doc;

}

Cheers to Tomas Restrepo for his insight into the CreateXmlInstance: http://www.winterdom.com/weblog/2008/07/16/CreateXmlInstanceWithMultiRootSchemas.aspx


Posted Fri, Aug 1 2008 7:15 AM by chilberto
Filed under: ,

Comments

wbovrv wrote re: BizTalk: Create Message based on deployed schema
on Mon, Dec 29 2008 8:08 PM

AVEFyR  <a href="mrvuarobjvjn.com/.../a>, [url=http://qibdyjegurkq.com/]qibdyjegurkq[/url], [link=http://kxbkmqqibgfz.com/]kxbkmqqibgfz[/link], http://vpvdwnjylllv.com/

cvndivibr wrote re: BizTalk: Create Message based on deployed schema
on Wed, Jan 7 2009 9:39 PM

pm2g20  <a href="rkxorkuurmzx.com/.../a>, [url=http://kgstwcsovxnj.com/]kgstwcsovxnj[/url], [link=http://vgfnwvhqucwo.com/]vgfnwvhqucwo[/link], http://bubitodrcctj.com/

Jeffrey Chilberto wrote BizTalk: CreateBTSMessage revisited
on Wed, Feb 4 2009 10:41 PM

This post is a follow-up to the previous BizTalk: Create Message based on deployed schema post. In the

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Please add 5 and 5 and type the answer here:
Copyright © 2003-2010 BloggingAbout.NET