Using C# to parse a SOAP Response
Posted
by Gavin
on Stack Overflow
See other posts from Stack Overflow
or by Gavin
Published on 2010-05-20T16:54:25Z
Indexed on
2010/05/20
17:20 UTC
Read the original article
Hit count: 201
I am trying to get the values for faultcode, faultstring, and OrderNumber from the SOAP below
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<faultcode>1234</faultcode>
<faultstring>SaveOrder:SetrsOrderMain:Cannot change OrderDate if GLPeriod is closed, new OrderDate is 3/2/2010:Ln:1053</faultstring>
<detail>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body UserGUID="test">
<m:SaveOrder xmlns:m="http://www.test.com/software/schema/" UserGUID="test">
<Order OrderNumber="1234-1234-123" Caller="" OrderStatus="A" xmlns="http://www.test.com/software/schema/">
Here is my code in C#
XDocument doc = XDocument.Load(HttpContext.Current.Server.MapPath("XMLexample.xml"));
var errorDetail = new EcourierErrorDetail
{
FaultCode = from fc in doc.Descendants("faultcode")
select fc.Value,
FaultString = from fs in c.Descendants("faultstring")
select fs.Value,
OrderNumber = from o in
doc.Descendants("detail").Elements("Order").Attributes("OrderNumber")
select o.Value
};
return errorDetail;
I am able to get the values for both faultcode and faultstring but not the OrderNumber. I am getting "Enumeration yielded no results." Can anyone help? Thanks.
© Stack Overflow or respective owner