Create message instance from multiroot XSD using DocumentSpec

Sometimes you’re in a situation where you need to create a message from scratch. Yossi Dahan wrote an excellent blog post on this topic. As shown by this post there are a number of options to achieve this.

 

 

One option is to use the undocumented BizTalk Document Specification (DocumentSpec) API. Although this way of creating a message has some obvious disadvantages (see also comments to Yossi’s blogpost) it can be the best option in certain specific situations.

On of the things you need to do to create a message instance is to create a new instance of the DocSpec class. The constructor of the DocumentSpec class takes the .Net/BizTalk schema type name and the assembly display name that contains the schema as parameters. The code should look something like this:

 

 

string assemblyDisplayName = “TestSchema, Version=1.0.0.0, Culture=neutral, publicKeyToken=xxxxxxxxxxxxxxxx”;  

string schemaName = “TestSchema.MyTestSchema”

DocumentSpec docSpec = new DocumentSpec(schemaName, assemblyDisplayName);

 

 

This code works fine for single root schemas but you’ll get an error of you try this for a multiroot schema (an xsd that has multiple root nodes):

 

 

 

 

 

So how can I make this code work for multi root schemas? It took me a while to find out but the solution is simple. Just add the name of the root node of the message you want to create preceeded by a ‘+’ sign:

 

string assemblyDisplayName = “TestSchema, Version=1.0.0.0, Culture=neutral, publicKeyToken=xxxxxxxxxxxxxxxx”;  

 

string schemaName = “TestSchema.MyTestSchema+myRootNode1

 

DocumentSpec docSpec = new DocumentSpec(schemaName, assemblyDisplayName);

 

 

This will provide the DocumentSpec class with all the information needed to create a message instance. 

Advertisement

One Response to Create message instance from multiroot XSD using DocumentSpec

  1. hxbergen says:

    Thanks, that helped me great, because you can not generate in xml instance in Visual Studio for a schema with multiple roots. (An instance of the first root is created always.)

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.