How to read xml returned by a WebService in a IE?
This how to shows how you can read the XML which is returned by a WebService and displayed in raw XML in IE.
fozylet submitted the solution for that question in the asp.net forums. I have converted his VB.NET code to C#.
Used Classes:
StreamReader
XmlDocument
HttpWebRequest
HttpWebResponse
Code:
void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
StreamReader StreamHandler;
XmlDocument xmlDoc = new XmlDocument();
string strURL = "http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD";
HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(strURL);
wRequest.Headers.Add("Man", "GET " + strURL);
HttpWebResponse wResponse = (HttpWebResponse)wRequest.GetResponse();
if(wRequest.HaveResponse){
if(wResponse.StatusCode == HttpStatusCode.OK){
StreamHandler = new System.IO.StreamReader(wResponse.GetResponseStream());
xmlDoc.LoadXml(StreamHandler.ReadToEnd());
Response.Write(xmlDoc.InnerText);
}
}
}
}
</script>
Output:
0.0218