Hello,
I have a C# application that is consuming a C# WebService. I am calling a method on the WebService and it is sending me back a response which contains an XmlDocument:
-
string soapMessage = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><soap:Body><validateStudent xmlns=\"http://tempuri.org/StudentResults/\"><studentID>" + txtStudentID.Text + "</studentID></validateStudent></soap:Body></soap:Envelope>";
-
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/StudentResults/Results.asmx");
-
XmlDocument doc = new XmlDocument();
-
-
doc.LoadXml(soapMessage);
-
-
req.ContentType = "text/xml; charset=utf-8";
-
req.Accept = "text/xml";
-
req.Method = "POST";
-
req.Headers.Add("SOAPAction", @"http://tempuri.org/StudentResults/validateStudent");
-
Stream stm = req.GetRequestStream();
-
doc.Save(stm);
-
stm.Close();
-
WebResponse resp = req.GetResponse();
-
stm = resp.GetResponseStream();
-
StreamReader r = new StreamReader(stm);
-
-
XmlDocument response = new XmlDocument();
-
response.LoadXml(r.ReadToEnd());
-
Problem I have is that the Stream response
- <?xml version="1.0" encoding="utf-8"?>
-
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
-
<soap:Body>
-
<validateStudentResponse xmlns="http://tempuri.org/StudentResults/">
-
<validateStudentResult>
-
<validateStudent xmlns="">
-
<studentID>1234</studentID>
-
<studentName>Andrew Harris</studentName>
-
</validateStudent>
-
</validateStudentResult>
-
</validateStudentResponse>
-
</soap:Body>
-
</soap:Envelope>
contains the SOAP envelope and I cant get the following XPath Query to return the relevant Node, the "name" XmlNode is always "Undefined"?
- XmlNamespaceManager nsm = new XmlNamespaceManager(response.NameTable);
-
nsm.AddNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");
-
nsm.AddNamespace("sr","http://tempuri.org/StudentResults/");
-
-
XmlNode currentNode = response.DocumentElement.FirstChild;
-
XmlNode name = currentNode.SelectSingleNode("/soap:Envelope/soap:Body/sr:validateStudentResponse/validateStudentResult/validateStudent/studentID", nsm);
Any help appreciated.
Regards
Andrew