WSDL - 允许 SOAP 消息的不同顺序的数据成员
WSDL - allow different order of DataMembers for SOAP messages
我们使用 ServiceStack 5.9.2。
DTO:
[DataContract]
[Restrict(Usage.SoapOnly)]
public class GetDocumentations : Documentations
{
}
[DataContract]
[Api("Abfrage auf von geplanten zu dokumentierenden Interventionen")]
public class Documentations
{
[DataMember]
[ApiMember(Description = "Ist dieses Feld gesetzt werden nur die Interventionen abgefragt, die sich seit dem letzten Acknowledge geändert haben.")]
public bool? OnlyChanged { get; set; }
[DataMember]
public DocumentationType Type { get; set; }
[DataMember]
public int[] SubTypeIds { get; set; }
[DataMember]
public int[] CustomerIds { get; set; }
[DataMember(IsRequired = true)]
public DateTime From { get; set; }
[DataMember(IsRequired = true)]
public DateTime To { get; set; }
[DataMember]
[ApiMember(Description = "Die Ergebnismenge wird auf x Elemente eingeschraenkt.")]
public int? Limit { get; set; }
}
生成的 WSDL 被截断:
<xs:complexType name="Documentations">
<xs:sequence>
<xs:element minOccurs="0" name="CustomerIds" nillable="true" xmlns:q28="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q28:ArrayOfint" />
<xs:element name="From" type="xs:dateTime" />
<xs:element minOccurs="0" name="Limit" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="OnlyChanged" nillable="true" type="xs:boolean" />
<xs:element minOccurs="0" name="SubTypeIds" nillable="true" xmlns:q29="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q29:ArrayOfint" />
<xs:element name="To" type="xs:dateTime" />
<xs:element minOccurs="0" name="Type" type="tns:DocumentationType" />
</xs:sequence>
</xs:complexType>
强制传入 soap 请求中的顺序与定义的一样:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap12:Body>
<GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<From>2014-01-01T00:00:00</From>
<Limit>100</Limit>
<OnlyChanged>false</OnlyChanged>
<To>2100-01-01T00:00:00</To>
<Type>CarePlan</Type>
</GetDocumentations>
</soap12:Body>
</soap12:Envelope>
有效,但以下无效,因为 Limit 属性 处于不同的位置:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap12:Body>
<GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<From>2014-01-01T00:00:00</From>
<OnlyChanged>false</OnlyChanged>
<To>2100-01-01T00:00:00</To>
<Type>CarePlan</Type>
<Limit>100</Limit>
</GetDocumentations>
</soap12:Body>
</soap12:Envelope>
此处忽略限制。意思是:它没有映射到它的 属性.
将 xs:sequence 更改为 xs:all 即可解决此问题。我们怎样才能做到这一点?或者有更好的解决方案吗?许多 DTO 都会出现此问题。
您可以更改字段的序列化和反序列化顺序 DataMember Order property, but the DataContractSerializer 不支持接受以任何顺序反序列化。
我们使用 ServiceStack 5.9.2。
DTO:
[DataContract]
[Restrict(Usage.SoapOnly)]
public class GetDocumentations : Documentations
{
}
[DataContract]
[Api("Abfrage auf von geplanten zu dokumentierenden Interventionen")]
public class Documentations
{
[DataMember]
[ApiMember(Description = "Ist dieses Feld gesetzt werden nur die Interventionen abgefragt, die sich seit dem letzten Acknowledge geändert haben.")]
public bool? OnlyChanged { get; set; }
[DataMember]
public DocumentationType Type { get; set; }
[DataMember]
public int[] SubTypeIds { get; set; }
[DataMember]
public int[] CustomerIds { get; set; }
[DataMember(IsRequired = true)]
public DateTime From { get; set; }
[DataMember(IsRequired = true)]
public DateTime To { get; set; }
[DataMember]
[ApiMember(Description = "Die Ergebnismenge wird auf x Elemente eingeschraenkt.")]
public int? Limit { get; set; }
}
生成的 WSDL 被截断:
<xs:complexType name="Documentations">
<xs:sequence>
<xs:element minOccurs="0" name="CustomerIds" nillable="true" xmlns:q28="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q28:ArrayOfint" />
<xs:element name="From" type="xs:dateTime" />
<xs:element minOccurs="0" name="Limit" nillable="true" type="xs:int" />
<xs:element minOccurs="0" name="OnlyChanged" nillable="true" type="xs:boolean" />
<xs:element minOccurs="0" name="SubTypeIds" nillable="true" xmlns:q29="http://schemas.microsoft.com/2003/10/Serialization/Arrays" type="q29:ArrayOfint" />
<xs:element name="To" type="xs:dateTime" />
<xs:element minOccurs="0" name="Type" type="tns:DocumentationType" />
</xs:sequence>
</xs:complexType>
强制传入 soap 请求中的顺序与定义的一样:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap12:Body>
<GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<From>2014-01-01T00:00:00</From>
<Limit>100</Limit>
<OnlyChanged>false</OnlyChanged>
<To>2100-01-01T00:00:00</To>
<Type>CarePlan</Type>
</GetDocumentations>
</soap12:Body>
</soap12:Envelope>
有效,但以下无效,因为 Limit 属性 处于不同的位置:
<?xml version="1.0" encoding="UTF-8"?>
<soap12:Envelope xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap12:Body>
<GetDocumentations xmlns="http://schemas.datacontract.org/2004/07/Company" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<From>2014-01-01T00:00:00</From>
<OnlyChanged>false</OnlyChanged>
<To>2100-01-01T00:00:00</To>
<Type>CarePlan</Type>
<Limit>100</Limit>
</GetDocumentations>
</soap12:Body>
</soap12:Envelope>
此处忽略限制。意思是:它没有映射到它的 属性.
将 xs:sequence 更改为 xs:all 即可解决此问题。我们怎样才能做到这一点?或者有更好的解决方案吗?许多 DTO 都会出现此问题。
您可以更改字段的序列化和反序列化顺序 DataMember Order property, but the DataContractSerializer 不支持接受以任何顺序反序列化。