zoukankan      html  css  js  c++  java
  • 在Eclipse中通过axis2调用网络免费webService服务

    上上一篇blog讲到了如何用axis2建立webService(sayHello),然后调用的方法。

    http://www.cnblogs.com/Jason_Chan/archive/2013/04/09/3010623.html

    这篇开始讲如何调用网络的webService服务。

    我们用到的免费IP服务:http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx(可以打开这个链接)

    image

    里面讲到了服务所提供的3个方法(参数,返回值)

    下面开始使用这些服务:

    1,建立一个Dynamic web project

    image

    2,利用上上一篇blog讲到的方法让axis2生成客户端代码

    http://www.cnblogs.com/Jason_Chan/archive/2013/04/09/3010623.html

    image

    这里网址填写上面的免费ip服务网址

    image

    之后根据之前blog讲到的知识一直到完成,会得到如下图的情况:

    image

    你们得到的结果肯定会有错误,是因为没有添加axis2的jar包

    添加axis2的lib下所有jar到当前项目里:

    image

    3, 使用生成的客户端代码:

    建立类文件:

    package org.web.ipmessage;
    
    import java.rmi.RemoteException;
    import cn.com.webxml.*;
    
    public class GetIPMessage {
    
    	/**
    	 * @param args
    	 */
    	public static void main(java.lang.String[] args) throws RemoteException{
    		// TODO Auto-generated method stub
    		java.lang.String target = "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx";
    		
    
    		IpAddressSearchWebServiceStub stub = new IpAddressSearchWebServiceStub(target);
    		GetCountryCityByIp getByIp = new GetCountryCityByIp();
    
    		getByIp.setTheIpAddress("216.13.14.220");
    		GetCountryCityByIpResponse eur = stub.getCountryCityByIp(getByIp);
    		java.lang.String[] result = eur.getGetCountryCityByIpResult().getString();
    		
    		System.out.println("IP:" + result[0]);
    		System.out.println("Msg:" + result[1]);
    		
    	}
    
    }

    运行(右键此类文件 Run As—>Java Application)

    image

    祝你们成功!

  • 相关阅读:
    C#生成唯一值的方法汇总
    Ajax && json在springmvc中的使用
    spring集成mybatis
    mybatis iBatis
    springjdbc
    拦截器
    系统分层
    Java反射(reflect)
    springmvc
    spring 之 使用注解简化配置
  • 原文地址:https://www.cnblogs.com/Jason_Chan/p/3010850.html
Copyright © 2011-2022 走看看