7.Web Service 调用天气代码
1.
2500多个城市天气预报 WEB服务公用事业
Endpoint:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx
Disco:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?disco
WSDL:http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl 代码如下: import java.rmi.RemoteException; import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException; import org.apache.axis.client.Call;
import org.apache.axis.client.Service; public class Weather {
public static void main(String[] args) throws ServiceException,
RemoteException {
String cityCode = "北京";
String userId = "";
// http://WebXml.com.cn/是wsdl中definitions根节点的targetNamespace属性
// webservice路径
// 这里后面加不加 "?wsdl" 效果都一样的
String endpoint = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
String[] res = null; // 查询城市天气的接口方法名
String operationName = "getWeather";
// 定义service对象
Service service = new Service();
// 创建一个call对象
Call call = (Call) service.createCall();
// 设置目标地址,即webservice路径
call.setTargetEndpointAddress(endpoint);
// 设置操作名称,即方法名称
call.setOperationName(new QName("http://WebXml.com.cn/", operationName));
// 设置方法参数
call.addParameter(new QName("http://WebXml.com.cn/", "theCityCode"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName("http://WebXml.com.cn/", "theUserID"),
org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
// 设置返回值类型
// 对于返回是字符串数组的返回类型只有这两种可行 // call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_VECTOR);
call.setReturnClass(java.lang.String[].class); call.setUseSOAPAction(true);
call.setSOAPActionURI("http://WebXml.com.cn/" + "getWeather"); res = (String[]) call.invoke(new Object[] { cityCode, userId }); // 如果返回类型是org.apache.axis.encoding.XMLType.SOAP_VECTOR时用下面的转型接收
// Vector v=(Vector) call.invoke(new Object[]{cityCode,userId});
for (String str : res) {
System.out.println(str);
}
}
}
7.Web Service 调用天气代码的更多相关文章
- IGS_学习笔记07_IREP通过页面测试客户化Web Service调用(案例)
20150819 Created By BaoXinjian
- IGS_学习笔记08_IREP通过soapUI测试客户化Web Service调用(案例)
20150819 Created By BaoXinjian
- 翻译-使用Spring调用SOAP Web Service
原文链接: http://spring.io/guides/gs/consuming-web-service/ 调用SOAP web service 本指南将指导你使用Spring调用一个基于SOAP ...
- C#使用SOAP调用Web Service
程序代码 using System;using System.IO;using System.Net;using System.Text; namespace ConsoleApplication1{ ...
- C#开发和调用Web Service
http://blog.csdn.net/h0322/article/details/4776819 1.1.Web Service基本概念 Web Service也叫XML Web Service ...
- ASP.NET调用Web Service
1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求, ...
- C# 调用 Web Service
Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术.是:通过SOAP ...
- 如何使用 JMeter 调用你的 Restful Web Service?进行简单的压力测试和自动化测试
表述性状态传输(REST)作为对基于 SOAP 和 Web 服务描述语言(WSDL)的 Web 服务的简单替代,在 Web 开发上得到了广泛的接受.能够充分证明这点的是主流 Web 2.0 服务提供商 ...
- .Net调用Java端带有WS-Security支持的Web Service各方案实战【转】
原文:http://www.xuebuyuan.com/641669.html 到现在为止,我们AEP平台已经发布很长一段时间了,也有很多ISV接入并上线了,就语言而言,目前主要有三类:Java..N ...
随机推荐
- Java类和对象9
(1)创建一个叫做机动车的类:属性:车牌号(String),车速(int),载重量(double)功能:加速(车速自增).减速(车速自减).修改车牌号,查询车的载重量.编写两个构造方法:一个没有形参, ...
- [转]Zen Cart官网屏蔽中国用户访问的真正原因
近需要到 zen cart 的官方网站查询一些资料,却发现无法访问!在网上搜索一番以后,原来如此. Zen Cart官网屏蔽中国用户访问的真正原因 作者:[鹏程万里] 日期:2011-03-26 准备 ...
- iOS——集成支付宝 ’openssl/asn1.h' file not found
问题原因:文件路径找不到的问题 解决方法:在 Building Settings -> Search Paths -> Header Search Paths 里,添加一个文件路径:$(P ...
- bzoj1293 [SCOI2009] 生日礼物 队列
题目描述 小西有一条很长的彩带,彩带上挂着各式各样的彩珠.已知彩珠有N个,分为K种.简单的说,可以将彩带考虑为x轴,每一个彩珠有一个对应的坐标(即位置).某些坐标上可以没有彩珠,但多个彩珠也可以出现在 ...
- Java Web MVC 一个实例的手动实现
平台: tomcat7.0 Servlet3.0 Windows命令行编译 实现的功能: 在网页上可以进行对Product类的三个属性的输入,点击保存之后跳转到另一个显示输入内容的界面 文 ...
- 【习题 8-20 UVA-1620】Lazy Susan
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 会发现,如果把连续4个数字进行一次翻转的话. 假设这连续的4个数字的逆序数为x; 那么翻转过后,逆序数就会变成6-x; (最多6个逆 ...
- Xwiki平台Windows搭建(Tomcat7 + XWiki6.2 + MySQL5.5)
背景介绍 国内xwiki安装使用资料较少,根据自己使用xwiki经验,总结出来,供参考,同时希望感兴趣的朋友能够一起讨论,XWiki是一个强大的Java开源的Wiki引擎. 它支持一些受欢迎的特性如: ...
- uip UDP server广播模式(client能够随意port,而且主动向client发送数据)
眼下移植uip,发现UDP server模式下,必须指定本地port以及clientport,否则仅仅能讲clientport设置为0,才干接收随意port的数据,可是无法发送数据,由于此时clien ...
- CO-PRIME(初探 莫比乌斯)NYOJ1066(经典)gcd(a,b)=1
CO-PRIME 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 This problem is so easy! Can you solve it? You are ...
- Visual Code的调试
Run 'Debug: Download .NET Core Debugger' in the Command Palette or open a .NET project directory to ...