0

can someone please tell me whitch of these xsd parts (xsd1 or xsd2) is valid for sample code below:

Class definitions:
class A
{
 int prop1;
 int prop2;
}

class B : A {}

So, class A is base class and class B inherit A and have no aditional properties.

xsd1: In this case if I use wsimport to generate code from wsdl file that contains this part of xsd I will get generated code for all elements, A and B. But, if I use svcutil I will get generated only class A.

<xs:element name="B" nillable="true" type="tns:A" />
<xs:complexType name="A">
    <xs:sequence>
        <xs:element name="prop1" type="xs:string"/>
        <xs:element name="prop2" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="A" nillable="true" type="tns:A" />

xsd1: In this case both wsimport and svcutil will generate all elements, A and B.

<xs:complexType name="B">
    <xs:complexContent mixed="false">
        <xs:extension base="tns:A">
            <xs:sequence />
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:element name="B" nillable="true" type="tns:A" />
<xs:complexType name="A">
    <xs:sequence>
        <xs:element name="prop1" type="xs:string"/>
        <xs:element name="prop2" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="A" nillable="true" type="tns:A" />

So, my question is ... is this first definition valid?

4

1 回答 1

1

我想正确的解决方案是第二种。解释为什么如果您将 complexTypes 视为类而将元素视为实例可能会更好。

在您的第一个 xsd 中,您实际上是在声明 A 类的两个实例(A 和 B)。在第二个中,您仍然声明同一类的两个实例,但您还包括 B 类的定义。

事实上,我想它会更正确

<xs:element name="B" nillable="true" type="tns:B" />

<xs:element name="B" nillable="true" type="tns:A" />
于 2012-07-19T13:35:43.287 回答