GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
WebException was unhandle  XML
Forum Index -> General
Author Message
mar_mayis



Joined: 01/03/2012 20:08:20
Messages: 1
Offline

Hi everybody

I am trying to use geoname's services to get the latitude and longitude from ZipCode, but all the times it felt down. i couldn't get the connection.

it is just waiting for localhost and finally it felt down on this step


var webResponse = (HttpWebResponse)request.GetResponse();

WebException was unhandle


this is my complete function

public string LookupCoordinates(string Zip, string Country)
{
string Lat = "";
string Lon = "";
string PostUrl = "http://ws.geonames.org/postalCodeSearch?postalcode=" + Zip + "&maxRows=10&country=" + Country;

var request = WebRequest.Create(PostUrl);
var webResponse = (HttpWebResponse)request.GetResponse();

if (webResponse.StatusCode == HttpStatusCode.OK)
{

StreamReader sr = new StreamReader(webResponse.GetResponseStream());
string Result = sr.ReadToEnd().Trim();
if (Result != "")
{
// Load the response into an XML doc
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(Result);
// Navigate to latitude node
XmlNodeList name = xdoc.GetElementsByTagName("lat");
if (name.Count > 0)
{
Lat = name[0].InnerText;
}
// Navigate to longitude node
name = xdoc.GetElementsByTagName("lng");
if (name.Count > 0)
{
Lon = name[0].InnerText;
}
}
}
return (Lat + "," + Lon);
}
geotree


[Avatar]
Joined: 23/07/2007 18:28:40
Messages: 138
Location: France
Offline

ws.geonames.org is deprecated for 13 months :
http://geonames.wordpress.com/2011/01/28/application-identification-for-free-geonames-web-services/

Christophe
geotree.geonames.org
geotree.geonames.org/geotree.html
[WWW]
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team