5. webservice通信调用天气预报接口实例
转自:https://blog.csdn.net/xiejuan6105/article/details/78452605
一:环境搭建
1:新建一个java project工程weatherInf
2:引入相应的jar包
activation.jar
axis-ant.jar
axis.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
log4j-1.2.8.jar
mail.jar
saaj.jar
wsdl4j-1.5.1.jar
下载axis 1.4 src压缩包,解压后到webapp/web-info/lib下取包,具体路径如下:
http://download.csdn.net/detail/yyg64/5351114
其中mail.jar 以及 activation.jar 可到如下路径下载:
http://download.csdn.net/detail/dbhunter/398258
3:将天气预报接口wsdl文件拷贝到src目录下
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
二:目录结构
三:根据wsdl文件生成客户端代码
wsdl文件——右键——web services——Generate Client,然后一路next到finish。
会生成如下客户端代码:
四:测试代码

1 /**
2 *
3 */
4 package com.paic.services;
5
6 import java.rmi.RemoteException;
7
8 import javax.xml.rpc.ServiceException;
9
10 import cn.com.WebXml.WeatherWebServiceLocator;
11 import cn.com.WebXml.WeatherWebServiceSoapStub;
12
13 /**
14 * @author Administrator
15 *
16 */
17 public class TestWeather {
18 public static void main(String[] args) throws ServiceException,
19 RemoteException {
20 WeatherWebServiceLocator locator = new WeatherWebServiceLocator();
21 WeatherWebServiceSoapStub service = (WeatherWebServiceSoapStub) locator
22 .getPort(WeatherWebServiceSoapStub.class);
23 invokeGetSupportProvince(service);
24 System.out.println("...................");
25 invokeGetSupportCity(service);
26 invokeGetWeatherByOneCity(service);
27 }
28
29 // 调用获取支持的省份、州接口
30 public static void invokeGetSupportProvince(
31 WeatherWebServiceSoapStub service) throws RemoteException {
32 String[] provices = service.getSupportProvince();
33 System.out.println("总共" + provices.length + "个");
34 int count = 0;
35 for (String str : provices) {
36 if (0 != count && count % 5 == 0) {
37 System.out.println();
38 }
39 System.out.print(str + "\t");
40 count++;
41 }
42 }
43
44 // 调用获取支持查询某个省份内的城市接口
45 public static void invokeGetSupportCity(WeatherWebServiceSoapStub service)
46 throws RemoteException {
47 String provinceName = "江苏";
48 String[] cities = service.getSupportCity(provinceName);
49 System.out.println("总共" + cities.length + "个市");
50 for (int i = 0; i < cities.length; i++) {
51 if (0 != i && i % 5 == 0) {
52 System.out.println();
53 }
54 System.out.print(cities[i] + "\t");
55 }
56 }
57
58 // 调用查询某个城市天气的接口
59 public static void invokeGetWeatherByOneCity(
60 WeatherWebServiceSoapStub service) throws RemoteException {
61 String cityName = "南京";
62 String[] weatherInfo = service.getWeatherbyCityName(cityName);
63 for (String str : weatherInfo) {
64 System.out.println(str);
65 }
66 }
67 }

五:得到结果
5. webservice通信调用天气预报接口实例的更多相关文章
- webservice通信调用天气预报接口实例
转载:http://www.cnblogs.com/warrior4236/p/5668449.html 一:环境搭建 1:新建一个java project工程weatherInf 2:引入相应的ja ...
- 关于Silverlight调用天气预报接口问题
问题:因Silverlight客户端不能直接调用webservice接口(外网天气接口),调用会出现跨域访问的问题,即使添加了跨域文件也不好使.解决方法如下 解决方法一:1.在服务端建立一个wcf服务 ...
- java调用天气预报接口案例
免费天气接口:http://mobile.weather.com.cn/data/sk/城市ID.html 例如: http://mobile.weather.com.cn/data/sk/10124 ...
- LoadRunner通过webservice协议调用WSDL接口时,返回值不正确
有可能是某些传参空的值导致的. 解决办法:注释掉空值传参.或者将其值转变为true ”ProductIDSpecified=true“,
- 基于JAVA的全国天气预报接口调用示例
step1:选择本文所示例的接口"全国天气预报接口" url:https://www.juhe.cn/docs/api/id/39/aid/87step2:每个接口都需要传入一个参 ...
- 【转载】C#调用国家气象局天气预报接口
一.需求 最近,刚好项目中有天气预报查询功能的需求,要求录入城市名称,获取该城市今日天气信息及相关气象生活辅助信息等. 例如:查询北京市天气 结果为: 今日北京天气:15℃~5℃ 阵雨转阴,北风3-4 ...
- C#调用国家气象局天气预报接口
原文:C#调用国家气象局天气预报接口 一.需求 最近,刚好项目中有天气预报查询功能的需求,要求录入城市名称,获取该城市今日天气信息及相关气象生活辅助信息等. 例如:查询北京市天气 结果为: 今日北京天 ...
- jQuery Ajax方法调用 Asp.Net WebService、WebMethod 的详细实例代码
将以下html存为ws.aspx <%@ Page Language="C#" AutoEventWireup="true" %> <scri ...
- VB调用WebService(SOA2.0接口)(直接Post方式)并解析返回的XML
SOA 2.0接口 Function GetDepartmentCode(reqDeptCode) Dim soaRequestXML : soaRequestXML = "" D ...
随机推荐
- CF1005F Berland and the Shortest Paths (树上构造最短路树)
题目大意:给你一个边权为$1$的无向图,构造出所有$1$为根的最短路树并输出 性质:单源最短路树上每个点到根的路径 ,一定是这个点到根的最短路之一 边权为$1$,$bfs$出单源最短路,然后构建最短路 ...
- react-native 编译 undefined is not an object (evaluating '_react2.PropTypes.func')
情况通报: 因为是我的二维码模块报错,提示报错代码如下 重要信息是下面的红色字体部分(Android 模拟器红屏) undefined is not an object (evaluating '_r ...
- RHEL8.0-beta-1.ISO
https://pan.baidu.com/s/1Yh_xuz39xGRrCtGtwhuqQg RHEL-8.0-beta-1-x86_64-dvd.iso 文件名: E:\rhel-8. ...
- 紫书 习题 8-25 UVa 11175 (结论证明)(配图)
看了这篇博客https://blog.csdn.net/u013520118/article/details/48032599 但是这篇里面没有写结论的证明, 我来证明一下. 首先结论是对于E图而言, ...
- 由老同事学习SAP所想到的
前段时间一位老同事在微信上跟我说他们公司正计划导SAP系统,但整个IT中心几乎无人使用过SAP,知道我在这行业干了多年了,所以想问我怎么开始学习.于是我约他今天出来聊聊,顺便把手里的SAP ECC E ...
- Ubuntu系统中中文的设置
这几天心血来潮,在实习公司真的没什么事情做,在学长的推荐下就学习了一下Ubuntu系统,感觉还是挺不错的,这个系统,所以我也推荐刚开始学习liunx系统的妹子们也可以先学一下这个. 1>你可以在 ...
- poj_1974,最长回文字串manacher
时间复杂度为O(n),参考:http://bbs.dlut.edu.cn/bbstcon.php?board=Competition&gid=23474 #include<iostrea ...
- lucene LZ4 会将doc存储在一个chunk里进行Lz4压缩 ES的_source便如此
默认情况下,Elasticsearch 用 JSON 字符串来表示文档主体保存在 _source 字段中.像其他保存的字段一样,_source 字段也会在写入硬盘前压缩.The _source is ...
- js中字符串下划线转为驼峰
function camelCase(string){ // Support: IE9-11+ return string.replace( /-([a-z])/g, function( all, l ...
- SQL流程控制语句
1 GoTo语句 IF 12>9GOTO print1ELSE GOTO print2 print1:PRINT '执行了流程1'--GOTO theEndprint2:PRINT '执行了流程 ...