Accessing all values in SOAP envelope
I have a SOAP response which looks like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<RegisterAccountResponse xmlns="http://site.com/services/player">
<RegisterAccountResult xmlns:a="http://site.com/entities/player/account"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Token i:nil="true" xmlns="http://site.com/contracts/common" xmlns:b="http://site.com/entities/communication"/>
<StatusCode xmlns="http://site.com/contracts/common">UserAlreadyExists</StatusCode>
<StatusMessage xmlns="http://site.com/contracts/common">
Customer with same name and date of birth already registered
</StatusMessage>
<a:PlayerAccount i:nil="true"/>
</RegisterAccountResult>
</RegisterAccountResponse>
</s:Body>
</s:Envelope>
which somehow manages to populate the following response class:
namespace Site.Messages.Player.Account
{
[DataContract(Namespace = "http://site.com/entities/player/account")]
public class RegistrationResponse : ResponseBase
{
/// <summary>
/// Gets or sets the player account.
/// </summary>
/// <value>The player account.</value>
[DataMember]
public PlayerAccount PlayerAccount { get; set; }
}
}
Response base:
namespace Site.Messages.Common
{
/// <summary>
/// Base class for all Request / Response classes.
/// </summary>开发者_如何学运维
[DataContract(Namespace = "http://site.com/contracts/common")]
public abstract class ResponseBase : RequestResponseBase
{
}
}
RequestResponseBase:
namespace Site.Messages.Common
{
/// <summary>
/// Base class for all Request / Response classes.
/// </summary>
[DataContract(Namespace = "http://site.com/contracts/common")]
public abstract class RequestResponseBase
{
public string StatusCode; //always null
public string StatusMessage; //always null
public Token Token;
}
}
It seems the following lines are responsible for kicking off this process:
ActivatedClient<Contracts.Player.IAccount> client = null;
try
{
client = new Activator().ConnectPlayerServiceAccount();
return client.Instance.RegisterAccount(request);
}
finally
{
if (client != null) client.Close();
}
This time around PlayerAccount
is null as the SOAP message specifies but usually there is a serialised object in there.
I have the following questions:
- How can I access the value of
StatusMessage
which is defined in the SOAP envelope? (I've added the property to the class with the same name but it is never populated) - How is this class even getting populated? (internal workings, rules etc)
Any pointers much appreciated - but as you can tell I am new to SOAP and just trying to understand somebody elses code.
If you look at the message that arrives the token is i:nil = "true" which is why your token is null
The StatusMessage and Message are siblings of the token in the message not children of it. You need to add StatusMessage and Message to RequestResponseBase for them to be populated
精彩评论