0

I am trying to access all elements int this SOAP response, but I am finding it difficult to access the elements inside the response. I am trying to use XmlNamespaceManager, but do not know how to go about it. Please can anyone give me an insight?

Below is the response;


<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header/>
    <soap:Body>
        <Result>
            <statuscode>200</statuscode>
            <Customer>10001252</Customer>
            <CustomerName>MBOKO FARMS</CustomerName>
            <CustomerFullName>MBOKO FARMS/0 ANAMBRA</CustomerFullName>
            <FiscalAddress/>
            <VATRegistration/>
        </Result>
    </soap:Body>
</soap:Envelope>

and also;

I tried using XmlNamespaceManager, but forming the addnamsespace is giving me tough time. I want to access the different elements from this response.

1 Answer 1

0

If you just need to read that message, then easy solution is to copy the whole message. Create a new cs file in Visual Studio, and clear it. Then Edit->Paste Special->Paste Xml As Classes.

Then


using System.Xml.Serialization;

internal class Program
{
    static void Main(string[] args)
    {
        Envelope envelope = Read(@"C:\temp\soap_xml.xml");

        var name = envelope.Body.Result.CustomerFullName;
    }


    private static Envelope Read(string file)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(Envelope));
        using (StreamReader reader = new StreamReader(file))
        {
            return (Envelope)serializer.Deserialize(reader)!;
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.