0
我面臨的情況是必須在數據類型上實現IXmlSerializable,我將通過WCF服務發送數據類型。但是,當我嘗試在xsd中標記基類時,服務引用不再被刷新,並且我正在爲「無法找到」寫入xsd。 這裏是XSD:在WCF中指定繼承XmlSchema
<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>"
這裏是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");
}
我想我需要以某種方式導入BASETYPE?
編輯: 我試過
var baseschemes = xs.Schemas("http://schemas.datacontract.org/2004/07/MyBase");
foreach (XmlSchema item in baseschemes)
{
s.Includes.Add(item);
}
它增加了一個模式(如預期),但沒有任何變化!
如何提供靜態XSD?我的BaseType是一個簡單的DataContract類,我沒有爲它寫任何XSD。我可以輸出嗎?我可以從XmlSchemaSet加載它嗎? – TDaver 2011-03-30 13:25:10
查看原文請參見我的新(不成功)想法 – TDaver 2011-03-30 13:43:45
WCF無法單獨導出它;由於您使用的是IXmlSerializable,因此根本無法知道您是否關心該基本類型。 – tomasr 2011-03-30 14:04:03