Home Page › Forums › BizTalk 2004 – BizTalk 2010 › CreateXMLInstance for generating wcf message
- This topic has 2 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
July 3, 2008 at 7:28 PM #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;
} -
July 15, 2008 at 7:08 AM #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.
-
July 16, 2008 at 5:24 PM #20177
Cheers Tomas for the response.
Worked perfectly; just need to change my method to accept a schema and root type name.
– Jeff
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.