webservice调用天气服务
常见服务:http://www.webxml.com.cn/zh_cn/support.aspx
可能用到缺少的ArrayOfString.java文件
package com.test.wes.weather; import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType; /**
* <p>ArrayOfString complex type的 Java 类。
*
* <p>以下模式片段指定包含在此类中的预期内容。
*
* <pre>
* <complexType name="ArrayOfString">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="string" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ArrayOfString", propOrder = {
"string"
})
public class ArrayOfString { @XmlElement(nillable = true)
protected List<String> string; /**
* Gets the value of the string property.
*
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the string property.
*
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getString().add(newItem);
* </pre>
*
*
* <p>
* Objects of the following type(s) are allowed in the list
* {@link String }
*
*
*/
public List<String> getString() {
if (string == null) {
string = new ArrayList<String>();
}
return this.string;
} }
wsimport用法
用法: wsimport [options] <WSDL_URI> \其中 [options] 包括:
-b <path> 指定 jaxws/jaxb 绑定文件或附加模式
(每个 <path> 都必须具有自己的 -b)
-B<jaxbOption> 将此选项传递给 JAXB 模式编译器
-catalog <file> 指定用于解析外部实体引用的目录文件
支持 TR9401, XCatalog 和 OASIS XML 目录格式。
-d <directory> 指定放置生成的输出文件的位置
-encoding <encoding> 指定源文件所使用的字符编码
-extension 允许供应商扩展 - 不按规范
指定功能。使用扩展可能会
导致应用程序不可移植或
无法与其他实现进行互操作
-help 显示帮助
-httpproxy:<host>:<port> 指定 HTTP 代理服务器 (端口默认为 8080)
-keep 保留生成的文件
-p <pkg> 指定目标程序包
-quiet 隐藏 wsimport 输出
-s <directory> 指定放置生成的源文件的位置
-target <version> 按给定的 JAXWS 规范版本生成代码
默认为 2.2, 接受的值为 2.0, 2.1 和 2.2
例如, 2.0 将为 JAXWS 2.0 规范生成兼容的代码
-verbose 有关编译器在执行什么操作的输出消息
-version 输出版本信息
-wsdllocation <location> @WebServiceClient.wsdlLocation 值
-clientjar <jarfile> 创建生成的 Artifact 的 jar 文件以及
调用 Web 服务所需的 WSDL 元数据。
-generateJWS 生成存根 JWS 实现文件
-implDestDir <directory> 指定生成 JWS 实现文件的位置
-implServiceName <name> 生成的 JWS 实现的服务名的本地部分
-implPortName <name> 生成的 JWS 实现的端口名的本地部分 \扩展:
-XadditionalHeaders 映射标头不绑定到请求或响应消息不绑定到
Java 方法参数
-Xauthfile 用于传送以下格式的授权信息的文件:
http://username:password@example.org/stock?wsdl
-Xdebug 输出调试信息
-Xno-addressing-databinding 允许 W3C EndpointReferenceType 到 Java 的绑定
-Xnocompile 不编译生成的 Java 文件
-XdisableAuthenticator 禁用由 JAX-WS RI 使用的验证程序,
将忽略 -Xauthfile 选项 (如果设置)
-XdisableSSLHostnameVerification 在提取 wsdl 时禁用 SSL 主机名
验证 \示例:
wsimport stock.wsdl -b stock.xml -b stock.xjb
wsimport -d generated http://example.org/stock?wsdl
平时的用法
wsimport -encoding utf-8 -p com.test.wes.weather -s . http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
但

先把文件下载下来WeatherWS.asmx
再WeatherWS.asmx里
<s:element ref="s:schema"/><s:any/>全部替换为 <s:any minOccurs="2" maxOccurs="2"/>
wsimport -encoding utf-8 -p com.test.wes.weather -s . WeatherWS.asmx
运行上面的句子,生成了下面代码

package com.test.wec; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List; import javax.xml.namespace.QName;
import javax.xml.ws.Service; import com.test.wes.phone.MobileCodeWSSoap;
import com.test.wes.weather.ArrayOfString;
import com.test.wes.weather.WeatherWS;
import com.test.wes.weather.WeatherWSSoap; public class ServiceClient { public static void main(String[] args) throws IOException {
//创建WSDL的URL,注意不是服务地址
// URL url = new URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl");
//
// //创建服务名称
// //1.namespaceURI - 命名空间地址
// //2.localPart - 服务视图名
// QName qname = new QName("http://WebXml.com.cn/", "qqOnlineWebService");
//
// //创建服务视图
// //参数解释:
// //1.wsdlDocumentLocation - wsdl地址
// //2.serviceName - 服务名称
// Service service = Service.create(url, qname);
// //获取服务实现类
//// QqOnlineWebServiceSoap qqonlineSsSoap =service.getPort(QqOnlineWebServiceSoap.class);
//// //调用查询方法
//// String result = qqonlineSsSoap.qqCheckOnline("1565465");
//// System.out.println(result); WeatherWS factory = new WeatherWS();
//根据工厂创建一个WeatherWSSoap对象
WeatherWSSoap weatherWSSoap = factory.getWeatherWSSoap();
//调用WebService提供的getWeather方法获取南宁市的天气预报情况
ArrayOfString weatherInfo = weatherWSSoap.getSupportCityString("广东");
List<String> lstWeatherInfo = weatherInfo.getString();
//遍历天气预报信息
for (String s : lstWeatherInfo) {
System.out.print(s+"|");
}
System.out.println(); ArrayOfString weatherInfo1 = weatherWSSoap.getWeather("广州", "");
List<String> lstWeatherInfo1 = weatherInfo1.getString();
//遍历天气预报信息
for (String s : lstWeatherInfo1) {
System.out.print(s+"|");
}
System.out.println(); }
}

webservice调用天气服务的更多相关文章
- webservice调用天气
class WebServiceHelper { /// <summary> /// 动态调用WebService /// </summary> /// <param n ...
- 使用WebService调用第三方服务
场景 某个系统服务由第三方提供,我方要使用到这个这个服务,就可以使用WebService的方式. 什么是WebService 关于什么WebService,官方是这么解释的: Web service是 ...
- php使用webservice调用C#服务端/调用PHP服务端
由于公司业务需要,用自产平台对接某大厂MES系统,大厂提出使用webservice来互通,一脸懵逼啊,一直没有使用过php的webservice的我,瞬间打开手册开始阅读,最终爬过无数坑之后,总结出如 ...
- 基于jdk调用天气服务案例及问题
问题1:解析wsdl文件时出现 把网络上的wsdl保存到本地,把圈起来的那段删掉 代码: 当返回结果不是String类型时: 输入城市编码去查找 所以: 问题二:如果把本地wsdl文件删除的话需要 三 ...
- 动态调用webservice及WCF服务
动态调用web服务,该方法只针对Web service, WCF的服务不行,如果是WCF的就通过工具直接生产代理类,把代理类配置到调用的项目中,通过配置客户端的终结点动态的取实现: 通过Svcutil ...
- Tomcat6.0+Jdk1.5+Axis1.3搭建java webservice环境,并使用c#调用该服务。
java jdk:jdk1.5.0_17 下载网址:http://pan.baidu.com/s/1gdmAkgV tomcat 6.0 下载地址:http://tomcat.apache.org/d ...
- Fiddler捕捉ASP.NET WebSite调用WebService、WCF服务
Fiddler默认会注册一个代理,有时会发现WebSite调用的WebService或者WCF服务无法被捕捉到.其实是由于运行的站点关联的应用程序池使用的账号和我们当前登陆操作系统的用户不同,自然它们 ...
- VC++ 使用MSSOAP访问WebService天气服务(客户端开发)
绪论 本文介绍使用VC++编程实现访问天气Web服务的简单实例(例子来源于网络). Web天气服务 http://www.webxml.com.cn/WebServices/WeatherWebSer ...
- 动态调用web服务
通常我们在程序中需要调用WebService时,都是通过“添加Web引用”,让VS.NET环境来为我们生成服务代理,然后调用对应的Web服务.这样是使工作简单了,但是却和提供Web服务的URL.方法名 ...
随机推荐
- SpringBoot系列——Filter 过滤器
前言 本文记录一下在SpringBoot项目中是如何使用Filter过滤器 代码.测试 Filter过滤器是servlet包下面的东西,因此我们不需要再额外引包 方法一 直接实现Filter接口,并使 ...
- PHP中发送qq邮件
<?php namespace app\home\logic; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Except ...
- Add an Item to the New Action 在新建按钮中增加一个条目
In this lesson, you will learn how to add an item to the New Action (NewObjectViewController.NewObje ...
- 剑指offer笔记面试题11----旋转数组的最小数字
题目:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如,数组{3, 4, 5, 1, 2}为{1, 2, 3, 4, 5 ...
- iOS sqlite ORM框架-LKDBHelper
LKDBHelper 一个sqlite ORM(全自动操作数据库)框架. 线程安全.不再担心递归锁死的问题 安装要求 iOS 4.3+ 仅支持 ARC FMDB 添加到你的项目 如果你使用 Cocoa ...
- TSPITR fails With RMAN-06553 (Doc ID 2078790.1)
TSPITR fails With RMAN-06553 (Doc ID 2078790.1) APPLIES TO: Oracle Database - Enterprise Edition - V ...
- How to restore and recover a database from an RMAN backup. (Doc ID 881395.1)
APPLIES TO: Oracle Database - Enterprise Edition - Version 10.1.0.2 to 11.2.0.2 [Release 10.1 to 11. ...
- FreeRTOS临界保护
下面的是个人笔记,所有的话都适用于我本人理解,可能存在不对的地方. 进入临界保护(支持嵌套):taskENTER_CRITICAL(); 退出临界保护(支持嵌套):taskEXIT_CRITICAL( ...
- CodeForces - 1251D (贪心+二分)
题意 https://vjudge.net/problem/CodeForces-1251D 您是一个大型企业的负责人.在您的企业当中共有n位员工为您工作,而且非常有趣的事是这个n是一个奇数(n不能被 ...
- JVM 类的加载机制
在对类的实例化之前.JVM 一般会先进行初始化 主要经过如下几个阶段: 1.加载 类加载的第一阶段,类加载时机有两个: 1.预加载:当虚拟机启动时,会预加载 ...