我正在尝试复制目前正在生产中的旧肥皂服务。合同,请求和响应必须是 exker 相同的,以便我们不需要更新使用此服务的所有依赖系统。这项旧的肥皂服务的问题是,其中一种反应很奇怪。它具有以下结构:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://something" xmlns:ns1="http://something1">
<soap:Body>
<ns:MyResponse>
<ns:GetInfo>
<ns1:IdNumber>12345</ns:IdNumber>
<ns1:PersondataList>
<ns1:FirstName>John</ns1:FirstName>
<ns1:LastName>Travolta</ns1:LastName>
</ns1:PersondataList>
</ns:GetInfo>
</ns:MyResponse>
</soap:Body>
</soap:envelope>
这个不死的使我想到了代码中的以下结构:
public class GetInfo
{
public string IdNumber {get; set;}
public PersonData[] PersondataList {get; set;}
}
public class PersonData
{
public string FirstName {get; set;}
public string LastName {get; set;}
}
在SOAPUI中测试此内容时,我的响应如下:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://something" xmlns:ns1="http://something1">
<soap:Body>
<ns:MyResponse>
<ns:GetInfo>
<ns1:IdNumber>12345</ns:IdNumber>
<ns1:PersondataList>
<ns1:Persondata>
<ns1:FirstName>John</ns1:FirstName>
<ns1:LastName>Travolta</ns1:LastName>
<ns1:Persondata>
</ns1:PersondataList>
</ns:GetInfo>
</ns:MyResponse>
</soap:Body>
</soap:envelope>
您可以看到,原始肥皂响应和我的复制之间的差异是FirstName
和LastName
之前的Persondata
标签。我认为这是正确的结构,但是如前所述,我需要以完全相同的方式复制响应...
如何产生与原始响应相同的结构?我需要写自己的序列化器吗?我有什么属性可以标记我的属性吗?
预先感谢。
对于那些绊倒这种类型的问题的人。将以下属性添加到您的属性:
[MessageBodyMember(Namespace = "Some namespace"), XmlElement]
最终结果:
public class GetInfo
{
public string IdNumber {get; set;}
[MessageBodyMember(Namespace = "Some namespace"), XmlElement]
public PersonData[] PersondataList {get; set;}
}