Reading XML or objects from a Web service
- by Shawn
This is my first time working with webservices and I am a bit lost.
I successfully called the functions, but I only can get one value from
the service. I read that the easiest way is to read xml or create objects
and then call their values. Currently I use functions that return the desired
value but I need to call them 3 times to get all the data witch is a waste of time
and resources. I tried to call the service with the URL and use it as a website
or getting the service to work the same way without importing into the program.
The thing is that i cant find a way to pass the values into the url, because of that
i get only blank pages. What is the fastest way to get my data from the services?
I need city name, temperature and a flag if the city is valid. I need to pass the zip
code to the service.
Thank you.
My current code
wetther.Weather wether = new wetther.Weather();
string farenhait = wether.GetCityWeatherByZIP(zip).Temperature;
string city = wether.GetCityWeatherByZIP(zip).City;
bool correct = wether.GetCityWeatherByZIP(zip).Success;
I tried it that way
// Retrieve XML document
XmlTextReader reader = new XmlTextReader("http://xml.weather.yahoo.com/forecastrss?p=94704");
// Skip non-significant whitespace
reader.WhitespaceHandling = WhitespaceHandling.Significant;
// Read nodes one at a time
while (reader.Read())
{
// Print out info on node
Console.WriteLine("{0}: {1}", reader.NodeType.ToString(), reader.Name);
}
This one works for the yahoo page but not for mine.
I need to use this webservice - http://wsf.cdyne.com/WeatherWS/Weather.asmx