[C#.NET][IP Location] 如何透過 FraudLabs Web Service 分析 IP Location

  • 3089
  • 0
  • 2013-08-16

[C#.NET][IP Location] 如何透過 FraudLabs Web Service 分析 IP Location

上篇是透過 Json API [C#.NET] 如何利用 JSON API 分析 IP Location來處理IP Location,本篇則是利用 http://www.fraudlabs.com/default.aspx 所提供的 Web Service 來處理,它能取得的欄位又更多,對於有需要的朋友是一大福音

IP2Location有三種版本Basic、Standard、Professional,不同的版本有不同的分析欄位,每個版本可以有每月90次的試用。

開始前要先註冊http://www.fraudlabs.com/userupdate.aspx,然後再取得Free License,註冊時需要用到E-Mail,好像只能用公司Domain的E-Mail帳號

image

 

image

PS.這還有許多其他的服務,有興趣的人可以自己玩玩

 

下載使用手冊

image

 

手冊上有寫著WS回傳的欄位是什麼,以及版本的差異

image

 

 

還有WS的位置:http://v1.fraudlabs.com/ip2locationwebservice.asmx?wsdl

image

 

Sample Code:http://www.fraudlabs.com/ip2locationsamplecodes.aspx

image

image

 


接下來就來實作

 

開一個新的專案,引用WS

image

 

使用WS的Method取得資訊

public IP2LocationOutput GetIp2LocationData(string IpAddress)
{
    if (string.IsNullOrEmpty(IpAddress))
        throw new ArgumentNullException("IpAddress");
    IPAddress address;
    if (!IPAddress.TryParse(IpAddress, out address))
        throw new FormatException("IpAddress");

    IP2LocationWebService factory = new IP2LocationWebService();
    IP2LocationInput ipInput = new IP2LocationInput();
    IP2LocationOutput ipOutput = new IP2LocationOutput();
    List<string> list = GetPropertyName<IP2LocationOutput>();
    try
    {
        ipInput.IP = IpAddress;
        ipInput.LICENSE = "數字自己申請的Key";
        //取得Location資訊
        ipOutput = factory.IP2Location(ipInput);
    }
    catch
    {
        throw;
    }
    return ipOutput;
}

若有謬誤,煩請告知,新手發帖請多包涵


Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET

Image result for microsoft+mvp+logo