在 WCF XmlSchema 中指定继承
我面临着一种情况,我必须在数据类型上实现 IXmlSerialized,我将通过 WCF 服务发送该数据类型。但是当我尝试在xsd中标记基类时,服务引用无法再刷新,并且我正在编写xsd的类型为“无法找到”。 这是 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>"
这是 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);
}
过添加一个架构(如预期),但没有任何变化!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您当前的 WSDL 没有告诉客户端在哪里可以找到 targetNamespace 为“http://schemas.datacontract.org/2004/07/BaseNS”的模式。您应该在 WSDL 中包含另一个元素,其中包含此名称空间的完整架构,或者提供一个引用静态 XSD 的元素。
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.