通过网上的webservice自己编写两个客户端

 

1.根据电话号码查询归属地等信息

  根据http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl采用jdk生成所需的代码,编写一个controller

@RestController
public class Controller {

    @RequestMapping("/phone")
    public String phone(HttpServletRequest request){
        String phone = request.getParameter("phone");
        //创建一个MobileCodeWS工厂
        MobileCodeWS factory = new MobileCodeWS();
        //根据工厂创建一个MobileCodeWSSoap对象
        MobileCodeWSSoap mobileCodeWSSoap = factory.getMobileCodeWSSoap();
        String searchResult = mobileCodeWSSoap.getMobileCodeInfo(phone, null);
        return searchResult;
    }
}

  运行项目,访问http://localhost:8800/phone?phone=18888888888  得到:18888888888:北京 北京 北京移动全球通卡

  代码下载:https://github.com/heqiyoujing/WebService

2.根据ip查询所属地

  根据http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl采用jdk生成所需的代码,编写一个controller

@RestController
public class Controller {

    @RequestMapping("/ip")
    public List<String> ip(HttpServletRequest request){
        String ip = request.getParameter("ip");
        IpAddressSearchWebService service = new IpAddressSearchWebService();
        IpAddressSearchWebServiceSoap soap = service.getIpAddressSearchWebServiceSoap();
        ArrayOfString ips = soap.getCountryCityByIp(ip);
        List<String> list = ips.getString();
        return list;
    }
}

  运行项目,访问http://localhost:9009/ip?ip=192.158.111.21  得到:["192.158.111.21","美国 "]

  代码下载:https://github.com/heqiyoujing/WebService

posted @ 2018-08-31 14:03  何其小静  阅读(411)  评论(0编辑  收藏  举报