加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 21:39:32 所属栏目:安全 来源:网络整理
导读:? 1.根据电话号码查询归属地等信息 根据http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl采用jdk生成所需的代码,编写一个controller @RestController public class Controller { @RequestMapping( "/phone" ) public String phone(HttpServletR

?

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读