How to read and parse SOAP XML from a Web Service in ASP.Net

Last Reply on Jan 24, 2014 04:27 AM By Azim

Posted on Jan 23, 2014 05:15 AM

How to read soap xml in asp.net

 

<espec:LoginEnvelope xmlns:espec="http://www.e-spec.net" enabled="false">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header/>
<soap:Body>
<m:AuthenticateUser xmlns:m="http://localhost/AdobeIntegration/ImportData.svc/Authenticate">
<m:username>uname</m:username>
<m:password>pwd</m:password>
<m:domain>dm</m:domain>
</m:AuthenticateUser>
</soap:Body>
</soap:Envelope>
</espec:LoginEnvelope>

 

Posted on Jan 24, 2014 04:27 AM Modified on on Jan 24, 2014 04:27 AM

REF:http://stackoverflow.com/questions/12201822/read-soap-message-using-c-sharp

Here i have created a xml file and pasted your soap xml data:

XML:

<espec:LoginEnvelope xmlns:espec="http://www.e-spec.net" enabled="false">
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
        <soap:Header/>
        <soap:Body>
            <m:AuthenticateUser xmlns:m="http://localhost/AdobeIntegration/ImportData.svc/Authenticate">
                <m:username>Azim</m:username>
                <m:password>pwd</m:password>
                <m:domain>dm</m:domain>
            </m:AuthenticateUser>
            <m:AuthenticateUser xmlns:m="http://localhost/AdobeIntegration/ImportData.svc/Authenticate">
                <m:username>Amir</m:username>
                <m:password>pwd</m:password>
                <m:domain>dm</m:domain>
            </m:AuthenticateUser>
        </soap:Body>
    </soap:Envelope>
</espec:LoginEnvelope>

In HTML i have a Label in that only i am displaying Username

<form id="form1" runat="server">
    <div>
        <asp:Label ID="lblNames" runat="server" />
    </div>
    </form>

C#:In page load i am reading the Xml file

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {            
            XmlDocument document = new XmlDocument();
            document.Load(Server.MapPath("XML/XMLFile.xml"));
            XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);                        
            manager.AddNamespace("bhr", "http://localhost/AdobeIntegration/ImportData.svc/Authenticate");
            XmlNodeList xnList = document.SelectNodes("//bhr:AuthenticateUser", manager);
            int nodes = xnList.Count;
            foreach (XmlNode xn in xnList)
            {
                lblNames.Text += xn["m:username"].InnerText + "<br />";
            } 
        }
    }

Thank You.