This HOW TO describes one of the various built-in methods .NET provides to use XML returned by a web service.
The simplest way to view the returned data is to get the response stream and put it into a string. This is especially handy for debugging. The following code gets a web page and put the the contents in a string.
public static string GetPageAsString(string address)
{
string result = string.Empty;
// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
// Get the web response
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
// Get the stream from response
StreamReader reader = new StreamReader(response.GetResponseStream());
// Read the whole contents and return as a string
result = reader.ReadToEnd();
reader.Dispose();
reader = null;
request = null;
return result;
}
To call this method write this code:
GetPageAsString("http://weather.yahooapis.com/forecastrss?p=ITXX0042&u=f");
Here there is the complete sourcecode.
GetXmlFromWebIntoString.rar (37.00 kb)