473,385 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

C#-XPath - Help with XPath Query and SOAP Response

2
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:
Expand|Select|Wrap|Line Numbers
  1. 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>";
  2. HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/StudentResults/Results.asmx");
  3. XmlDocument doc = new XmlDocument();
  4.  
  5. doc.LoadXml(soapMessage);
  6.  
  7. req.ContentType = "text/xml; charset=utf-8";
  8. req.Accept = "text/xml";
  9. req.Method = "POST";
  10. req.Headers.Add("SOAPAction", @"http://tempuri.org/StudentResults/validateStudent");
  11. Stream stm = req.GetRequestStream();
  12. doc.Save(stm);
  13. stm.Close();
  14. WebResponse resp = req.GetResponse();
  15. stm = resp.GetResponseStream();
  16. StreamReader r = new StreamReader(stm);
  17.  
  18. XmlDocument response = new XmlDocument();
  19. response.LoadXml(r.ReadToEnd());
  20.  
Problem I have is that the Stream response
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.   <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">
  3.     <soap:Body>
  4.       <validateStudentResponse xmlns="http://tempuri.org/StudentResults/">
  5.         <validateStudentResult>
  6.           <validateStudent xmlns="">
  7.             <studentID>1234</studentID>
  8.             <studentName>Andrew Harris</studentName>
  9.           </validateStudent>
  10.         </validateStudentResult>
  11.       </validateStudentResponse>
  12.     </soap:Body>
  13. </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"?

Expand|Select|Wrap|Line Numbers
  1. XmlNamespaceManager nsm = new XmlNamespaceManager(response.NameTable);
  2. nsm.AddNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");
  3. nsm.AddNamespace("sr","http://tempuri.org/StudentResults/");
  4.  
  5. XmlNode currentNode = response.DocumentElement.FirstChild;
  6. XmlNode name = currentNode.SelectSingleNode("/soap:Envelope/soap:Body/sr:validateStudentResponse/validateStudentResult/validateStudent/studentID", nsm);
Any help appreciated.

Regards

Andrew
May 13 '07 #1
2 7269
hary
2
Anyone able to help?
May 14 '07 #2
kenobewan
4,871 Expert 4TB
Have you tried stripping the soap envelope?
May 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Barring | last post by:
Hi All, I am new to XPath stuff. I want parse XMLDocument with XPath and find out subset of information. If you look at following xml, for i.e how can i retrieve subset information such as...
1
by: jeffreyv | last post by:
Hi! Here's a XML reprensenting a company. I would like to make a XPath query that gives me all the employees that are Programmer or Analyst and have 5 years of experience. I did the following...
2
by: mel_dev | last post by:
All, I'm brand new to XML and have been given a deadline to deliver some new functionality part of which requires stepping through an xml doc. I have hit a wall with the way I've structured an...
4
by: Christian Wilhelm | last post by:
Hi! I have a Problem understanding the deserialisation of SOAP-Responses. The "normal" way, calling a XML WebService is to use WSDL 1) Send Request 2) Get SOAP-Response 3) With Informations...
3
by: 0to60 | last post by:
Please help! I'm using the following code to get an XML doc: string str = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=12345&city=addison"; System.Net.HttpWebRequest request =...
1
by: Gregor D. | last post by:
Hi, I want to consume an Apache Webservice with a C# .NET Client. Everything works fine, but I'm having problem with the deserialization of the complex type "Item" that is included in the...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to construct an XPath query against an XML document, for a requirement that I have. Below is the XML fragment: <SUBMISSIONS> <SUBMISSION YEAR="2004"> <MONTH...
5
by: tschulken | last post by:
I have a query where i need to look for a value of a lower level xml element based on the value of a parent element existing first. Here is a simple example of the xml <S3Client> <Buttons>...
3
by: rajasekharsiva | last post by:
hi all, i am new to .net i have problem i have an xml fille lik this::: <?xml version="1.0" encoding="utf-8"?> <personal_info> <personal_id ID="1"> <name first_name="rajasekhar"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.