When creating schemas I typically follow the rule that each xsd file contains one root node only.

However when dealing with schemas that have been generated from metadata it is quite common for schemas to be generated with multipe root nodes.  In the case of web services all the request and response schema definitions across all the operations would be generated in one file, and similar behavior would be observed when generating schemas for the WCF-SQL adapter.  I would recommend sticking with this file structure, as it will minimize the pain you need to go through in case you need to regenerate the schemas and just want to overwrite the existing files.

How bad a typist does one have to be to misspell HelloWorld?

By default when you deploy a project that contains one of these multi root node schemas, all the schemas are available to the BizTalk runtime.

What you’ll quickly find though is that if you try to use options such as validate instance or generate instance, BizTalk will always do so with the first root node defined in the xsd file.   Luckily there is a way to override this by changing the “Root Reference” property against the schema.  You will see this property by clicking on the “Schema” node which is at the top of the schema hierarchy and then looking in the properties section of Visual Studio.

If you click on the dropdown, you will be faced with a list of all the root nodes in the schema file.  Choosing one of the root nodes will now instruct Visual Studio to treat that root node as the only valid one for that schema file.

The implication of this is that you can now run validate instance and generate instance against that schema file for the root node you have specified.  However another implication is that when you do a deployment from Visual Studio, you will find that only the root node that was set in root reference has been deployed, the rest of the root nodes are not available to the BizTalk runtime.

Where have all the schemas gone?

So moral of the story is that Root Reference is a powerful property that will allow you to validate or generate instances of the correct root node in your schema file, and can also be used to only deploy one of the root nodes defined in the schema file.  If you want to deploy all the root nodes in the schema file, do remember to set the Root Reference property back to (Default).

Advertisements