导航

根据XsdName创建Message

Posted on 2008-12-18 10:16  鸡尾虾的壳  阅读(166)  评论(0)    收藏  举报

using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.ExplorerOM;

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=myBizTalkMgmtDb;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;
}