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 ...
随机推荐
- Example of working with a dump.
Let's say that you are looking at a crash dump, so following the first command from this page you do ...
- NodeJS学习笔记 进阶 (13)Nodejs进阶:5分钟入门非对称加密用法
个人总结:读完这篇文章需要5分钟,这篇文章讲解了Node.js非对称加密算法的实现. 摘录自网络 地址: https://github.com/chyingp/nodejs-learning-guid ...
- Studio3T 破解,无需命令计划任务
最近项目中使用到了MongoDB,苦于命令行不好操作,所以就寻觅了一下MongDB的GUI管理工具,最终找到了Studio3T,功能非常强大,但是苦于只有评估版本30天,最可气的是一时手贱,修改了系统 ...
- POJ-2142 The Balance 扩展欧几里德(+绝对值和最小化)
题目链接:https://cn.vjudge.net/problem/POJ-2142 题意 自己看题吧,懒得解释 思路 第一部分就是扩展欧几里德 接下来是根据 $ x=x_0+kb', y=y_0- ...
- JDBC连接ORACLE无法登陆java.sql.SQLException: ORA-01017: invalid username/password; logon denied
当用jdbc连接Oracle数据库的时候 private Connection getConnection() throws SQLException { OracleDataSource ods = ...
- 一次Linux LVM VG丢失完整找回过程记录
某客户的一台PC服务器连接了一台HP EVA 的FC SAN存储,划了一个6T的LUN分作一个单独的VG使用,在某一次异常掉电之后,发现该VG完全丢失,使用vgs/pvs/lvs命令均无法找到此VG及 ...
- OpenJDK源码研究笔记(八)-详细解析如何读取Java字节码文件(.class)
在上一篇OpenJDK源码研究笔记(七)–Java字节码文件(.class)的结构中,我们大致了解了Java字节码文件的结构. 本篇详细地介绍了如何读取.class文件的大部分细节. 1.构造文件 ...
- unity C# StackOverflowException
有时候图省事,属性这样写public int pageCount{get{return pageCount;}set{pageCount=value;}}可能会报栈溢出的错误, StackOverfl ...
- vue.2.0-路由
vue2.0 路由: http://router.vuejs.org/zh-cn/index.html 基本使用: 1. 布局 <router-link to="/home" ...
- DMA在FPGA的应用之我见
首先,来做一个简单的实验,利用DMA来实现on-chip-memory和SRAM之间的传输,同时也在做一个关于SRAM不同地址之间的传输. 一.硬件设计 1.首先设计自己的SOPC结构,包括CPU.j ...