To read a message from SOAP in C#, we can use the XDocument class provided by "System.Xml.Linq". The other namespaces are "System.Xml" and "System.Xml.Serialization". Here is a custom code snippet where the first parameter is the SOAP response and the second parameter is the node name which you want to read.
- public static string GetSoapMessage(string soapBody, string nodeName)
- {
- XNamespace soapNameSpace
- = XNamespace.Get("YOUR SOAP NAMESPACE URL");
- var document = XDocument.Parse(soapBody);
- var soapMessage = document?.Root?.Descendants()?.Where(p =>
- p.Name.LocalName.Equals(nodeName) && p.Name.Namespace
- == soapNameSpace).FirstOrDefault()?.ToString();
- soapMessage = soapMessage?.Replace("xmlns:urn=", "xmlns=")
- .Replace("<urn:", "<")
- .Replace("</urn:", "</");
- return soapMessage;
- }

Kunal shahPosted Sep 27, 2021, 7:36 PM
Hi i want to read request body in wcf can you share any working example for that
Steve GavrillesPosted Jul 13, 2020, 12:24 PM
What is nodeName?