Click here to Skip to main content
16,005,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Every Body
Please Help Me
My Application is C# windows Application &
When i use yahoo web service it return xml result , how can i get information from it and how to return result as aweb page to be loaded in web browser
Posted

1 solution

u can use XmlDocument to obtain the web service result and then get values from it. Include following namespaces:
C#
using System.Net;
using System.IO;
using System.Xml;

Try this type of code:
C#
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/WebServiceDemo/DemoWebService.asmx/Add?x=50&y=12");
HttpWebResponse res = (HttpWebResponse)req.GetResponse();

XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(new StreamReader(res.GetResponseStream()).ReadToEnd());

lblResponse.Text = xdoc.OuterXml;

if (File.Exists("D:\\Demo.xml"))
	File.Delete("D:\\Demo.xml");
xdoc.Save("D:\\Demo.xml");

You can use xml class methods to get data from selected node using xdoc.SelectNodes or xdoc.SelectSingleNode methods and providing XPath in it.

Suppose web service result contains value in node "Value" inside root element "Root", then:
C#
lblResult.Value = xdoc.SelectSingleNode("Root/Value").InnerText;
 
Share this answer
 
Comments
[no name] 16-Nov-12 1:19am    
thanks can you write read example
xml such that:

<yweather:location city="Paris" region="" country="France">
<yweather:units temperature="C" distance="km" pressure="mb" speed="km/h">
<yweather:wind chill="3" direction="0" speed="3.22">
<yweather:atmosphere humidity="93" visibility="2.7" pressure="1015.92" rising="0">
<yweather:astronomy sunrise="8:00 am" sunset="5:06 pm">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900