# Wednesday, May 07, 2003
Here's an interesting scenario:
I started out with an XSD schema, lets call it myObject.xsd. Using xsd.exe, I generated a set of classes to represent the objects in the schema. Straighforward so far...

This part works fine, and I can read and write the objects using the XmlSerializer just as I would expect. The issues started when I tried to get SOAP and WSDL involved. I wanted to return one of the objects definied in myObject.xsd (and correspondingly in myObject.cs) from a Web Service method.

   [WebMethod()]    public myObject ReturnMyObject(){}

The WebService class has an attribute specifying its namespace

   [WebService(Namespace="http://me.com/MyNamespace")]    public class MyWebService : WebService{}

When I try to create a proxy class for the web service using either wsdl.exe, or VS.NET 2003, I get an error claiming that the type myObject is not defined, the schema can't be validated, and no classes will be generated.

It turns out that the crux of the matter was that when I wrote myObject.xsd, I didn't explicitly define a targetNamespace, so when xsd.exe generated the classes, it added an XmlRootAttribute(Namespace="") This conflicts with the namespace specified for the service, so when the WSDL gets generated by the framework, it's no wonder the schemas don't all line up.

Once I went back and fixed the targetNamespace in the schema, everything worked just fine. It makes sense why this would be an issue, but it certainly took a while to track down.

Comments are closed.