开发者

Specifying inheritance in WCF XmlSchema

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" targetNamespa开发者_开发技巧ce="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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜