Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm trying to access Country information using geonames webservice. When I type the url in the browser, i'm getting the output in xml format but same url is not accessible from the code.

Url is: http://ws.geonames.org/countryInfo?lang=it&country=DE[^]

code:
C#
XElement rootXml = XElement.Load("http://ws.geonames.org/countryInfo?lang=it&country=DE");

var Countries = from C in rootXml.Elements()
                select new
                {
                  Code = (string)C.Element("countryCode"),
                  Name = (string)C.Element("countryName")
                };

foreach (var x in Countries)
  Console.WriteLine("{0} {1}", x.Code, x.Name);

Console.ReadKey();


Error that i'm getting when the project is executed:
The remote name could not be resolved: 'ws.geonames.org'

Any help would be appreciated.
Posted
Updated 7-Jun-11 23:46pm
v2
Comments
RakeshMeena 8-Jun-11 5:53am    
Are you sitting behind a proxy?
NishaPai 8-Jun-11 6:29am    
I'm not sure. What if Yes? Does it causes any problem?
NishaPai 8-Jun-11 6:36am    
And the webservice i'm using is a REST webservice. No webreference is added nor the proxy is created.

1 solution

I pasted your code into an app, and it worked fine:
DE Germania
output to the console.
Have you tried single stepping?
 
Share this answer
 
Comments
NishaPai 8-Jun-11 5:40am    
Thanks for the reply. But I'm not sure of what Single stepping is. Can you kindly brief me what I need to do.
OriginalGriff 8-Jun-11 5:44am    
Put a break point on the first line of the code (the "XElement.Load" statement).
Run your program, and execution should stop when it hits that line.
You can then single-step through each instruction, checking variables as you go. (The default VS key is F10)
NishaPai 8-Jun-11 5:47am    
Oh yeah. You meant debugging. I tried that. The very first line will throw that exeption.
NishaPai 8-Jun-11 5:48am    
Actually, i have given a breakpoint at Page_Load event but before that only i'm getting the error!!
OriginalGriff 8-Jun-11 5:53am    
Then the error is coming from some other part of your code. Is it throwing an exception? If so, then in VS go to "Debug" on the menu, select "Exceptions" and tick every box in the dialog that comes up. Press OK and run your app again: It should now break on every exception, handled or not - which should let you find the actual line that is causing the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900