Wednesday, November 24, 2004

XSD.exe and namespaces

I've spent many hours this afternoon tracking down a schema issue - the classic "The part or fragment may not exist in the database." exception that means that a message cannot be resolved to a known schema. This is usually caused by having deployed two identical schema, or by not having deployed the schema at all.

A common fix is to undeploy and redeploy all schemas. This wouldn't work in my case, and I even went as far as reconfiguring BizTalk (and deleting all the databases).

Unfortunately this still didn't fix the issue, which was really confusing, as I only had two assemblies deployed, so it shouldn't have been too hard to work through all the available schemas!

I eventually tracked it down to a local web service that I was calling from within an orchestration. I'd used the BizTalk xsd schema and the xsd.exe tool to create the .cs file containing all of the classes behind my test web service. The web service worked fine through WebServiceStudio, so I knew that it was working.

The problem is that xsd.exe applies the same schema target namespaces to the System.Xml.Serialization.Xml*Attribute attibutes, which meant that I had a namespace clash through the imported Reference.xsd in the orchestration.

So - when using xsd.exe to create classes, always check the namespace attributes.

No comments: