调用根据IP查看城市WebService
添加引用:http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx
.cs代码
//IP查询省市
protected void BindIP(string strIP) { IpAddressSearchWebServiceSoap IpSearch = new IpAddressSearchWebServiceSoapClient("IpAddressSearchWebServiceSoap"); string[] infos = IpSearch.getCountryCityByIp(strIP); char[] strcity = { ' ' }; string[] str = infos[1].ToString().Split(strcity); //infos[1] 显示的是全部 Response.Write("IP是:"+infos[0]+" IP所在城市是:"+str[0]); } protected void btnIP_Click(object sender, EventArgs e) { string strip = txtIP.Text; BindIP(strip); } html代码aspx <asp:TextBox ID="txtIP" runat="server"></asp:TextBox> <asp:Button ID="btnIP" runat="server" Text="IP查询城市" onclick="btnIP_Click" />
第二种方法:
1.添加引用:http://www.wjg121.cn/service/ipaddress.asmx
2.protected void Page_Load(object sender, EventArgs e)
{
IPServer.PAddressSoapClient paddres = new IPServer.PAddressSoapClient("IPAddressSoap");
string st = paddres.GetIPCountry("117.89.57.254");
}