根据XsdName创建Message

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

你可能感兴趣的:(message)