How do you parse a soap Message with c# .net link
C# QUESTION
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raj KumarPosted Apr 4, 2011, 1:48 AM
{
List
elementNamesList.Add("Product");
elementNamesList.Add("StockNumber");
elementNamesList.Add("InventoryCount");
elementNamesList.Add("ProductDescription");
try
{
string elementNamespace = "ns0:MyWebService_myResponseElement";
// Get the root element of the SOAP message.
XElement rootElement = soapDocument.Root;
// Get values from SOAP message.
foreach (string elementName in elementNamesList)
{
//string messageNamespace = String.Format("{{{0}}}", elementNamespace);
//string searchFor = String.Format("{0}{1}", messageNamespace, elementName);
// Select element based upon search value.
var selectedElements = from elements in rootElement.Descendants()
where (elements.Name == elementName)
select elements;
foreach (XElement element in selectedElements)
{
string elementValue = element.Value;
string printValue = String.Format("{0} = {1}", elementName, elementValue);
Console.WriteLine(printValue);
}
}
}
catch (Exception ex)
{
Console.WriteLine("");
Console.WriteLine("-----");
Console.WriteLine("Error");
Console.WriteLine("-----");
Console.WriteLine(ex.ToString());
}
}