I am receiving a response from a web Request as a string that in fact is an XML, and this response can be different according to the Request that I send. It can be an XML with Success nodes or Error nodes.
What's the best way to handle this in my code?
Can I turn this String as an object to access each node of the response?
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns1:myService xmlns:ns1="http://site.de/alpm">
<ns1:Response>
<ns1:OrganisationData>
<ns1:ClientId>myID</ns1:ClientId>
<ns1:UserId>service</ns1:UserId>
<ns1:Pass>myPass</ns1:Pass>
</ns1:OrganisationData>
<ns1:TransactionData>
<ns1:TrxId>tg0rta1a1-6fh-hfh5-ryyb-ryyt56</ns1:CSDBTrxId>
<ns1:TimeOfProcessing>2018-11-28T13:09:41.179Z</ns1:TimeOfProcessing>
</ns1:TransactionData>
<ns1:Error>
<ns1:ReturnCode>lpt-978-jh</ns1:ReturnCode>
<ns1:Description>my description</ns1:Description>
</ns1:Error>
</ns1:Response>
</ns1:myService>
</soap:Body>
</soap:Envelope>
What changes is the <ns1:Error></ns1:Error>
, in case of sucess it will be a new tag.
How can I deal with this in my code. Dont forget that I am receiving this as a String? This is the code, the string is "myResult":
using (var webResponse = soapRequest.EndGetResponse(asyncResult))
{
string myResult;
var responseStream = webResponse.GetResponseStream();
if (responseStream == null)
{
return null;
}
using (var reader = new StreamReader(responseStream))
{
myResult = reader.ReadToEnd();
}
}