我认为来自delphi xe3的wsdl导入器似乎为某个wsdl / xsd生成了错误的代码。 Web服务本身不是由我们制作的,但我们需要使用它。我从我们提供的xsd模式中删除了相关部分来说明问题。
这是我认为会导致问题的XSD的一部分
<xs:element name="request">
<xs:complexType>
<xs:sequence>
<xs:element type="Demand" name="demand" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Demand" abstract="true">
<xs:sequence>
<xs:element name="person" type="Person" minOccurs="1" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Person" abstract="true">
<xs:sequence>
<xs:element name="name" minOccurs="0" maxOccurs="1">
</xs:sequence>
<xs:attribute name="key" type="xs:ID" use="required" />
</xs:complexType>
<xs:complexType name="MoralPerson">
<xs:complexContent>
<xs:extension base="Person">
<xs:sequence>
<xs:element name="juridicalForm">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:maxInclusive value="10" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="GarnishmentDemand">
<xs:complexContent>
<xs:extension base="Demand">
<xs:sequence>
<xs:element name="saleTotalAmount" type="Amount" minOccurs="1" maxOccurs="1" />
<xs:element name="saleDate" type="xs:date" minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
这里是delphi生成的一些代码
Person = class(TRemotable)
private
Fkey: string;
Fname_: name_;
Fname__Specified: boolean;
procedure Setname_(Index: Integer; const Aname_: name_);
function name__Specified(Index: Integer): boolean;
published
property key: string Index (IS_ATTR) read Fkey write Fkey;
property name_: name_ Index (IS_OPTN) read Fname_ write Setname_ stored name__Specified;
end;
MoralPerson = class(Person)
private
FjuridicalForm: juridicalForm;
published
property juridicalForm: juridicalForm read FjuridicalForm write FjuridicalForm;
end;
Demand = array of Person;
CreateNoticeOneRequest = class(TRemotable)
private
Fdossier: Dossier;
Fdemand: Demand;
public
destructor Destroy; override;
published
property demand: Demand read Fdemand write Fdemand;
end;
GarnishmentDemand = class(TRemotable)
private
FsaleTotalAmount: Amount;
FsaleDate: TXSDate;
public
destructor Destroy; override;
published
property saleTotalAmount: Amount read FsaleTotalAmount write FsaleTotalAmount;
property saleDate: TXSDate read FsaleDate write FsaleDate;
end;
当我查看XSD时,需求类型似乎是所有其他需求类型的基类,并且只包含一个人数组,因此所有派生类(如GarnishmentDemand)应该有一个人数组。问题是delphi将Demand类型本身声明为一个人数组,我认为它应该是一个类,所以当我创建一个GarnishmentDemand时我无法访问person数组。
这是wsdl导入程序中的错误,我看到它全部错误还是wsdl / xsd提供的错误?如果它是一个bug可以以某种方式纠正?我尝试在按下完成之前更改de wsdl导入器工具中的众多选项,但是Demand类型始终被声明为person而不是类的数组。
如果它不是一个bug,那么我在使用GarnishmentDemand类型时看不出我应该如何访问people数组?
答案 0 :(得分:0)
我找到了解决此问题的解决方案。
我在xsd中为Demand类型添加了一个虚拟元素,如下所示:
<xs:complexType name="Demand" abstract="true">
<xs:sequence>
<xs:element name="person" type="Person" minOccurs="1" maxOccurs="unbounded" />
<xs:element name="dummy" type="xs:boolean" minOccurs="0" maxOccurs="1" nillable="true"/>
</xs:sequence>
</xs:complexType>
然后我在delphi XE3中再次导入了wsdl / xsd,并从生成的代码中删除了虚拟元素。 Delphi现在将Demand类型定义为一个类,并且所有其他需求(如GarnishmentDemand)继承自Demand类,并且我能够像第一次那样访问person数组
Demand = class(TRemotable)
private
Fperson: Array_Of_Person;
Fdummy: Boolean;
Fdummy_Specified: boolean;
procedure Setdummy(Index: Integer; const ABoolean: Boolean);
function dummy_Specified(Index: Integer): boolean;
public
destructor Destroy; override;
published
property person: Array_Of_Person Index (IS_UNBD) read Fperson write Fperson;
property dummy: Boolean Index (IS_OPTN or IS_NLBL) read Fdummy write Setdummy stored dummy_Specified;
end;
GarnishmentDemand = class(Demand)
private
FsaleTotalAmount: Amount;
FsaleDate: TXSDate;
public
destructor Destroy; override;
published
property saleTotalAmount: Amount read FsaleTotalAmount write FsaleTotalAmount;
property saleDate: TXSDate read FsaleDate write FsaleDate;
end;
我将测试delphi XE4是否包含相同的bug,如果有,我会看看我是否可以使用embarcaderro QA提交报告