常见服务: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>
* &lt;complexType name="ArrayOfString">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* &lt;sequence>
* &lt;element name="string" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded" minOccurs="0"/>
* &lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/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调用天气服务的更多相关文章

  1. webservice调用天气

    class WebServiceHelper { /// <summary> /// 动态调用WebService /// </summary> /// <param n ...

  2. 使用WebService调用第三方服务

    场景 某个系统服务由第三方提供,我方要使用到这个这个服务,就可以使用WebService的方式. 什么是WebService 关于什么WebService,官方是这么解释的: Web service是 ...

  3. php使用webservice调用C#服务端/调用PHP服务端

    由于公司业务需要,用自产平台对接某大厂MES系统,大厂提出使用webservice来互通,一脸懵逼啊,一直没有使用过php的webservice的我,瞬间打开手册开始阅读,最终爬过无数坑之后,总结出如 ...

  4. 基于jdk调用天气服务案例及问题

    问题1:解析wsdl文件时出现 把网络上的wsdl保存到本地,把圈起来的那段删掉 代码: 当返回结果不是String类型时: 输入城市编码去查找 所以: 问题二:如果把本地wsdl文件删除的话需要 三 ...

  5. 动态调用webservice及WCF服务

    动态调用web服务,该方法只针对Web service, WCF的服务不行,如果是WCF的就通过工具直接生产代理类,把代理类配置到调用的项目中,通过配置客户端的终结点动态的取实现: 通过Svcutil ...

  6. 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 ...

  7. Fiddler捕捉ASP.NET WebSite调用WebService、WCF服务

    Fiddler默认会注册一个代理,有时会发现WebSite调用的WebService或者WCF服务无法被捕捉到.其实是由于运行的站点关联的应用程序池使用的账号和我们当前登陆操作系统的用户不同,自然它们 ...

  8. VC++ 使用MSSOAP访问WebService天气服务(客户端开发)

    绪论 本文介绍使用VC++编程实现访问天气Web服务的简单实例(例子来源于网络). Web天气服务 http://www.webxml.com.cn/WebServices/WeatherWebSer ...

  9. 动态调用web服务

    通常我们在程序中需要调用WebService时,都是通过“添加Web引用”,让VS.NET环境来为我们生成服务代理,然后调用对应的Web服务.这样是使工作简单了,但是却和提供Web服务的URL.方法名 ...

随机推荐

  1. PalletOne调色板跨链的ETH提币实现

    实现区块链的跨链,最主要的诉求就是Token的转移,而Token的跨链转移又分为充币和提币2种操作.以PalletOne调色板来说,如果要把ETH跨链到PalletOne上来流转,就是ETH的充币操作 ...

  2. RocketMQ 升级到主从切换(DLedger、多副本)实战

    目录 1.RocketMQ DLedger 多副本即主从切换核心配置参数详解 2.搭建主从同步环境 3.主从同步集群升级到DLedger 3.1 部署架构 3.2 升级步骤 3.3 验证消息发送与消息 ...

  3. jmap 导出 tomcat 内存快照分析

    登录系统(注意这里启动 tomcat 的用户) # 获取 tomcat 的 pid 号 ps -ef|grep tomcat # 例如这里 pid 号为 13133 jmap -dump:live,f ...

  4. golang-方法和接口

    1.方法 方法类似函数 ,多了一个接收者 ,接收者是指针指向结构体(也可以是值) ,方法与结构体绑定 (可以理解为模板定义方法) ,方法位于结构体内部 方法集可以理解就是多个方法 可以组合其他结构体方 ...

  5. hadoop免登录

    参考:http://wenku.baidu.com/link?url=n4PT7AhGnV7N8KevSEAMcCVGEaYqTuKmNodCQsUnR7qtAnWM0WDs8pFYLOpCUu9R9 ...

  6. TICK技术栈(四)Grafana安装及使用

    1.什么是Grafana? Grafana是一款采用go语言和Angular框架编写的开源的可视化工具,主要用于大规模指标数据的可视化展示,提供包括折线图,饼图,仪表盘等多种监控数据可视化UI,是网络 ...

  7. bash的基本特性

    1.命令历史 作用:查看之前使用的命令 关于命令历史的文件 每个用户家目录下面的.bash_history 在关机的时候,会自动写入一次(history -r 将内存中的命令历史写入文件) 关于命令历 ...

  8. Java使用JDBC连接SQL Server数据库

    Java使用JDBC连接SQL Server数据库 1.下载驱动 1.下载Microsoft SQL Server JDBC 驱动程序 https://docs.microsoft.com/zh-cn ...

  9. 重装windows后如何恢复mysql服务

    如果重装系统后之前的mysql还在的话,可又直接恢复,不需要安装: 注意my.ini文件的位置,应该与bin目录同级: 进入cmd,然后进入你的mysql的bin目录,输入命令:mysqld inst ...

  10. WPF 精修篇 数据绑定 更新通知

    原文:WPF 精修篇 数据绑定 更新通知 开始更新一点有意思的了 首先 数据绑定  其中之一 Element 绑定 看例子 <Window x:Class="WpfApplicatio ...