CreateXMLInstance for generating wcf message

Home Page Forums BizTalk 2004 – BizTalk 2010 CreateXMLInstance for generating wcf message

Viewing 1 reply thread
  • Author
    Posts
    • #20073

      Is it possible to use the DocumentSpec.CreateXmlInstance(StreamWriter) or a similar mechanism to generate a message instance where no root reference is specified and the schema contains multiple root nodes?  For example, against a WCF generated xsd.

      The code below is an example that works against a schema that contains a single root node or a schema that has multiple root nodes with a root reference specified.

      public static XmlDocument CreateBTSMessage(string schemaName)
      {
                  XmlDocument doc = new XmlDocument();
                  DocumentSpec docSpec;

                  BtsCatalogExplorer catalog = new BtsCatalogExplorer();
                  catalog.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[BTS_CONNECTION_STRING].ConnectionString;

                  Schema schema = catalog.Schemas[schemaName];

                  Microsoft.BizTalk.
                  if (schema != null)
                  {
                      docSpec = new DocumentSpec(schemaName, 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;
              }

    • #20153

      Jeff,

      From what I remember, DocumentSpec basically wraps a compiled schema, which is one or more types. When you compile a schema with multiple root nodes, each root_node becomes an actual type (a nested class, actually). You should be able to make this work by specifying as the schema name the right name: Full Namespace.SchemaTypeName+RootTypeName.

      Seems to work fine for me in a simple test I just ran.

      • #20177

         Cheers Tomas for the response. 

        Worked perfectly; just need to change my method to accept a schema and root type name. 

        – Jeff

Viewing 1 reply thread
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.