0

I'm faced with a situation where I have to implement IXmlSerializable on a datatype, which I'll send through WCF service. But when I try to mark the base class in the xsd, the service reference can no longer be refreshed, and the type I'm writing the xsd for "cannot be found". Here is the xsd:

<xs:schema 
xmlns:tnsg="http://schemas.datacontract.org/2004/07/MyNS" 
elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/MyNS" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:base="http://schemas.datacontract.org/2004/07/BaseNS">
  <xs:complexType name="MyType">
    <xs:extension base="base:BaseType">
        <xs:sequence>
            <xs:element name="BProperties">
              <xs:complexType>
                <xs:sequence>
                  <xs:element minOccurs="0" name="BInfo" nillable="true" type="xs:string" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element name="AProperties">
                <xs:complexType >
                    <xs:sequence>
                      <xs:element minOccurs="0" name="AStuff" nillable="true" type="xs:string" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:extension>
  </xs:complexType>
  <xs:element name="MyType" nillable="true" type="MyType" />
</xs:schema>"

Here is the C#:

public static XmlQualifiedName GetMySchema(XmlSchemaSet xs)
{
   XmlSchema s =  XmlSchema.Read(new StringReader(xsd), (sender, eargs) => {  });
   xs.Add(s);
   return new XmlQualifiedName("MyType", "http://schemas.datacontract.org/2004/07/MyNS");
}

I assume I need to import BaseType somehow?

EDIT: I've tried

  var baseschemes = xs.Schemas("http://schemas.datacontract.org/2004/07/MyBase");
  foreach (XmlSchema item in baseschemes)
  {
      s.Includes.Add(item);
  }

it adds one schema (as expected), but nothing changes!

TDaver
  • 7,164
  • 5
  • 47
  • 94

1 Answers1

0

The problem is that your current WSDL isn't telling the client where to find a schema with a targetNamespace of "http://schemas.datacontract.org/2004/07/BaseNS". You should either include another element into your WSDL that contains the full schema for this namespace, or provide a that references an static XSD with it.

tomasr
  • 13,683
  • 3
  • 38
  • 30
  • How to provide a static XSD? My BaseType is a simple DataContract class, I've written no XSD for it. Can I export it? Can I load it from the XmlSchemaSet? – TDaver Mar 30 '11 at 13:25
  • See original post pls for my new (unsuccessful) ideas – TDaver Mar 30 '11 at 13:43
  • WCF couldn't possibly export it on its own; since you're using IXmlSerializable, it has no way of knowing you cared about that base type at all. – tomasr Mar 30 '11 at 14:04
  • I think you should be able to use XsdDataContractExporter to generate the required schema, though: http://msdn.microsoft.com/en-us/library/system.runtime.serialization.xsddatacontractexporter.aspx – tomasr Mar 30 '11 at 14:04
  • With calling xs.Schemas(...) on the XmlSchemaSet I was able to find the already generated schema for my BaseType, but I couldn't add it to the current schema (kept getting exceptions). How do I add it to the current? s.Includes.Add(schema) + ? No combination seemed to work! – TDaver Mar 30 '11 at 14:06