How to Run third party Web service and get return example http://freegeoip.net

View previous topic View next topic Go down

How to Run third party Web service and get return example http://freegeoip.net

Post  Admin on Wed Feb 06, 2013 12:58 pm

How to run and how to process return response in xml/json

Admin
Admin

Posts : 50
Join date : 2009-06-05

View user profile http://softro.forumotion.net

Back to top Go down

Solution:

Post  Admin on Wed Feb 06, 2013 12:58 pm

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Xml;
using System.Data;

namespace IntellibizERP5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// string myExternalIP;
// string strHostName = System.Net.Dns.GetHostName();
// string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
// string clientip = clientIPAddress.ToString();
// System.Net.HttpWebRequest request =
//(System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.whatismyip.org");
// request.UserAgent = "User-Agent: Mozilla/4.0 (compatible; MSIE" +
// "6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
// System.Net.HttpWebResponse response =
// (System.Net.HttpWebResponse)request.GetResponse();
// using (System.IO.StreamReader reader = new
// StreamReader(response.GetResponseStream()))
// {
// myExternalIP = reader.ReadToEnd();
// reader.Close();
// }
// lblIp.Text = myExternalIP.ToString();
DataTable dt = GetLocation();
foreach(DataRow row in dt.Rows){
Response.Write("IP=" + row["Ip"].ToString());
Response.Write("CountryCode=" + row["CountryCode"].ToString());
Response.Write("CountryName=" + row["CountryName"].ToString());
Response.Write("RegionCode=" + row["RegionCode"].ToString());
Response.Write("MetroCode=" + row["MetroCode"].ToString());

}
}

private DataTable GetLocation()
{
WebRequest rssReq = WebRequest.Create("http://freegeoip.net/xml");
WebProxy px = new WebProxy("http://freegeoip.net/xml", true);
rssReq.Proxy = px;
rssReq.Timeout = 2000;
try
{
WebResponse rep = rssReq.GetResponse();
XmlTextReader xtr = new XmlTextReader(rep.GetResponseStream());
DataSet ds = new DataSet();
ds.ReadXml(xtr);
return ds.Tables[0];
}
catch
{
return null;
}
}
}
}

Admin
Admin

Posts : 50
Join date : 2009-06-05

View user profile http://softro.forumotion.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum