eclipse生成webService客户端进行接口调用

使用eclipse客户端生成WebService客户端进行接口调用:

new ->

Web Service Client ->

输入服务地址,例如:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl ->

next查看生成项目路径 ->

finish

此接口生成的项目文件如图:

 

接口调用:

URL url = new URL("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
WeatherWebServiceLocator service = new WeatherWebServiceLocator();
WeatherWebServiceSoapStub stub = new WeatherWebServiceSoapStub(url, service);
String[] city = stub.getSupportCity("ALL");
String[] weatherbyCityName = stub.getWeatherbyCityName("上海");
System.out.println(Arrays.toString(weatherbyCityName));

结果:

[直辖市, 上海, 16℃/27℃, 4月16日 多云转中雨, 南风4-5级, 1.gif, 8.gif, 今日天气实况:气温:25℃;风向/风力:东北风 1级;湿度:32%;紫外线强度:中等。空气质量:良。, 紫外线指数:中等,涂擦SPF大于15、PA+防晒护肤品。

健臻·血糖指数:易波动,风力较大,血糖易波动,注意监测。

穿衣指数:舒适,建议穿长袖衬衫单裤等服装。

洗车指数:不宜,有雨,雨水和泥水会弄脏爱车。

空气污染指数:良,气象条件有利于空气污染物扩散。

, 15℃/22℃, 4月17日 小雨转阴, 西风3-4级转西北风小于3级, 7.gif, 2.gif, 15℃/20℃, 4月18日 小雨转中雨, 东风3-4级, 7.gif, 8.gif, 上海简称:沪,...。]

 

maven项目引入依赖:

<!-- webservices -->
        <!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/axis/axis-jaxrpc -->
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.xml.soap/saaj-api -->
        <dependency>
            <groupId>javax.xml.soap</groupId>
            <artifactId>saaj-api</artifactId>
            <version>1.3.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery -->
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>

 

 

JDK自己内置了一个wsimport工具

wsimport -encoding utf-8 -s d:/ws -p com.app.webservice.client -keep http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl

-keep:是否生成java源文件

-d:指定输出目录,必须是存在的目录

-s:指定源代码输出目录

-p:以package的形式生成文件

-verbose:在控制台显示输出信息 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值