2017-03-01 57 views
1

我试图复制一个旧的soap服务,此服务正在生产中。合同,请求和响应必须是确切相同,所以我们不需要更新所有使用此服务的依赖系统。这个旧的soap服务的事情是,其中一个反应很奇怪。它具有以下结构:WCF响应 - 响应中的列表序列化

<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> 

这immiditaly让我在代码思维以下结构:

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> 

如您所见,原始肥皂响应和我的复制之间的区别是FirstNameLastName之前的Persondata标记。我认为这是正确的结构,但如前所述,我需要以完全相同的方式复制响应...

如何生成与原始响应相同的结构?我是否需要编写自己的序列化程序?有没有可以标记我的属性的属性?

在此先感谢。

回答

1

对于那些绊倒这类问题的人。下面的属性添加到您的属性:

[MessageBodyMember(Namespace = "Some namespace"), XmlElement] 

最终结果是:

public class GetInfo 
{ 
    public string IdNumber {get; set;} 

    [MessageBodyMember(Namespace = "Some namespace"), XmlElement] 
    public PersonData[] PersondataList {get; set;} 
}