I have store locator web service in which i'm using Google Map's HTTP request to get geocode information for given address. I'm not using Google's javascript object. I exposed a Webservice with one WebMethod that takes address as parameter. we pass that address to google as querystring using .Net HTTPRequest object and get the HTTRreponse object. Once i get the Geocode information in Response object i pass it to StoredProc and do the remaining magic there. and finally we return the result to our client.
this is how my code look like
// build google URL here using given address, output and applicationid
// URL = http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=csv&key=abcdefg
// pass this URL to GetWebResponse(string URL)
private string GetWebResponse(string URL)
{
System.IO.StreamWriter wr = null;
System.IO.StreamReader rd = null;
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
System.Web.HttpContext context = System.Web.HttpContext.Current;
request.Referer = context.Request.ServerVariables["HTTP_REFERER"];
request.Method ="POST";
request.ContentLength = URL.Length;
wr = new System.IO.StreamWriter(request.GetRequestStream());
wr.Write(URL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
rd = new System.IO.StreamReader(response.GetResponseStream());
return rd.ReadToEnd();
}
finally
{
if(wr != null)
wr.Close();
if(rd != null)
rd.Close();
}
}
this works fine. what i wanted to know is there any other alternate way to get back string without using HTTPRequest object & HTTPResponse object.
For example if i change output key to output=xml i'll get xml response from google and then i can use following code to read the response
XmlReader reader = new XmlTextReader(url);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(reader);
in this case xDoc will have response xml without creating HttpRequest & HttprResponse