How do you parse a soap Message with c# .net link
C# QUESTION
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raj KumarRank #25 · 44.2K reputationPosted Apr 3, 2011, 9:48 PM EDT
{
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());
}
}