In this article we will learn how to get all the cities by countries using an ASP.NET Web Service without a database.
BackgroundSometimes there is a need to get all the major cities of each country so most of the time its very difficult to manage such a type of huge database. To avoid this problem there is a free web service we can use to do it.Let us see step-by-step how to do this.Step 1: Locate Web Service
The following is the web service URL from which you can get the major cities by country name:http://www.webservicex.net/globalweather.asmx?WSDLStep 2: Create the web applicationTo use a Web Service at the client side we need to create a web application or another type of application such as Windows, console and so on but in this example we will create the web application.Let us create the web application as:
The source of the preceding web site will look like as:
In the preceding screen if a valid country is entered then on the change event of the TextBox it will display all the major cities of the given country.Step 3: Consume Web Service in the web applicationNow the next step is to consume the GetCitiesByCountry web service in our web application. The following is the URL of the GetCitiesByCountry Web services.http://www.webservicex.net/globalweather.asmx?WSDLAdding a Web Service Reference to the ASP.NET Web ApplicationThe most important task when consuming a Web Service in any application is to add the Web Service reference into the application. So how to add it? Let us see the procedure.
Our GetCitiesByCountry Web service URL is http://www.webservicex.net/globalweather.asmx?WSDL now we will paste it into the following window and after pasting it click on the forward arrow that will discover the web service class that is in our Web Service.
Similarly you can see the cities of any valid country name.In the preceding examples, you saw how to get the major city names of any country without a database using a free web service.Notes:
SummaryI hope that beginners as well as students understand how to get the major cities of any country using a free web service without any database. I hope its useful for all of you, if you have any suggestion regarding this article then please contact me. Student suggestions are also welcomed.
Pro WPF: Windows Presentation Foundation in .NET 3.0