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 ...
随机推荐
- Android Button 按钮 设置 各种状态 图片 颜色
有2个方法可以实现,一种是用 选择器 定义每种状态的图片 selec.xml <?xml version="1.0" encoding="utf-8"?& ...
- 显示gif动画(帧动画的播放)
在android上显示gif不太方便,虽然有控件可以实现,但是效果不是很好,保险点儿的作法还是使用帧动画来处理.①在XML中定义animation-list:<?xml version=&quo ...
- windows下MySQL5.6以上版本,如何通过修改配置文件来修改数据库的最大连接数啊?
并没有my.ini文件,只有一个my-default.ini文件,并且里面并没有max_connections windows下MySQL5.6以上版本,如何通过修改配置文件来修改数据库的最大连接数啊 ...
- 用Electron开发企业网盘(一)--通信
效果展示 项目背景: 由于浏览器的限制,web批量下载体验不好以及无法下载文件夹.采用Electron技术,通过js开发PC应用程序,着力解决批量下载.断点续传.文件夹下载等问题.配合网页版网盘使用, ...
- 洛谷3871 [TJOI2010]中位数 维护队列的中位数
题目描述 给定一个由N个元素组成的整数序列,现在有两种操作: 1 add a 在该序列的最后添加一个整数a,组成长度为N + 1的整数序列 2 mid 输出当前序列的中位数 中位数是指将一个序列按照从 ...
- oracle创建静态监听
[oracle@localhost admin]$ pwd /u01/app/oracle/product/11.2.0/dbhome_1/network/admin [oracle@localhos ...
- request.getxxxxxx()的使用方法
request.getSchema() 可以返回当前页面使用的协议,http 或是 https; request.getServerName() 可以返回当前页面所在的服务器的名字; request. ...
- 紫书 例题 10-25 UVa 1363(找规律)
可以发现余数是成一段一段的等差数列的. 在商数同的时候,余数是成首项为第一个数的余数,公差 为商数的等差数列. 利用这个性质求解即可. #include<cstdio> #include& ...
- centos的终端字体杂乱的问题
sudo yum -y install dejavu-sans-* dejavu-serif-fonts 下载字体一下就好了
- android 选取部分 log 的两种方法
Grep多个条件: android logcat -v time | grep -e A -e B 选取多个android log tag: android logcat -v time -s TAG ...