Reputation: 8981
I'm trying to replicate an old soap service, which is in production at the moment. The contract, requests and responses has to be the exact same so that we dont need to update all dependent systems which is using this service. The thing with this old soap service, is that one of the responses are pretty weird. It has the following structure:
<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>
This immiditaly makes me thinking of the following structure in code:
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;}
}
When testing this in SoapUI, my response are the following:
<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>
As you can see, the difference between the original soap response and my replication is the Persondata
tag before FirstName
and LastName
. In my opinion this is the correct structure, but as mentioned before, I need to replicate the response in the exact same way...
How can I produce the same structure as the original response? Do I need to write my own Serializer? Is there any attributes that I can mark my properties with?
Thanks in advance.
Upvotes: 1
Views: 63
Reputation: 8981
For those of you stumbling upon this type of problems. Add the following attribute to your property:
[MessageBodyMember(Namespace = "Some namespace"), XmlElement]
The end result:
public class GetInfo
{
public string IdNumber {get; set;}
[MessageBodyMember(Namespace = "Some namespace"), XmlElement]
public PersonData[] PersondataList {get; set;}
}
Upvotes: 1