WebserviceX.net provides a wide range of webservices, that can be used freely in development. GeoIPService is one webservice available with them that can be used to display the users country information that he/she was browsing from.
A small example on how to use the webservice (GeoIPService) in asp.net development. Create a new Project in Visual Studio. Right click on the project in the Solution Explorer and Click Add Web reference. In the Add Web Reference dialog box, enter the following url in the URL: box and click Go button.
http://www.webservicex.net/geoipservice.asmx?wsdl
If the webservice is found, the information will be displayed in the respective boxes. Click on Add Reference button. By default the web service will be added with the following namespace
net.webservicex.www
The required webserive files will be added automatically in the App_WebReferences folder created under the root of your application. You will see the geoipservice.discomap and geoipservice.wsdl added under the net >> webservicex >> www folder.
Note: geoipservice.discomap and geoipservice.wsdl are the discovery and webservice definition language files, that provides the necessary methods and classes.
Now , we use the classes and methods provided by the webservice in our page to display the country information like name etc..
Here is a sample listing on how to use in the aspx page (C# code)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using net.webservicex.www;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// set the current country name
StringBuilder _stringToDisplay = new StringBuilder();
GeoIPService _gipService = new GeoIPService();
GeoIP _geoIP = _gipService.GetGeoIP(Request.UserHostAddress.ToString());
_stringToDisplay.Append(_geoIP.CountryName);
_stringToDisplay.Append(" [" + _geoIP.CountryCode + "] ");
lblCountryName.Text = _stringToDisplay.ToString();
}
}
A sample of this implementation can be seen in my home page
http://www.g9th.com in the top right corner.
-Electronic Screw