jax-ws开发总结
服务端开发步骤:
1.定义SEI,即java中的接口
2.定义SEI的实现类,使用@webservice注解标记它是一个webservice服务类
3.发布服务
客户端开发步骤:使用jdk的service类,调用webservice
1.使用wsimport根据wsdl生成客户端调用代码
2.将生成的代码拷贝到工程中
服务端开发过程:
自定义实体类+注解开发
实体类:
package entity; import java.util.Date; /**
* 实体类
*/
public class Pojo {
//温度
private String detail;
//日期
private Date date;
//最高
private int temperature_max;
//最低
private int temperature_min;
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getTemperature_max() {
return temperature_max;
}
public void setTemperature_max(int temperature_max) {
this.temperature_max = temperature_max;
}
public int getTemperature_min() {
return temperature_min;
}
public void setTemperature_min(int temperature_min) {
this.temperature_min = temperature_min;
} }
接口1:
package service; import java.util.List; import entity.Pojo; /**
* 接口,查询天气
*/
public interface WeatherInterface { public List<Pojo> queryWeather(String cityName); }
实现类:
package service; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService; import com.sun.org.glassfish.gmbal.ParameterNames; import entity.Pojo; /**
* 接口实现类
*/ @WebService(serviceName="PojoService",
portName="PojoPort",
name="PojoPortType",
targetNamespace="http//:Pojo"
//endpointInterface="service.WeatherInterface2"
//wsdlLocation="http://127.0.0.1:12345/weather"
) public class Impl implements WeatherInterface{ // @WebMethod(operationName="queryPojo",exclude=true)
@Override
public @WebResult(name="result")List<Pojo> queryWeather(@WebParam(name="cityName")String cityName) { List<Pojo> list = new ArrayList<Pojo>(); //日历附件
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DATE); Pojo pojo1 = new Pojo();
pojo1.setDetail("晴1");
pojo1.setDate(new Date());
pojo1.setTemperature_max(5);
pojo1.setTemperature_min(-6); Pojo pojo2 = new Pojo();
pojo2.setDetail("晴2");
calendar.set(Calendar.DATE, day+1);
pojo2.setDate(calendar.getTime());
pojo2.setTemperature_max(5);
pojo2.setTemperature_min(-6); Pojo pojo3 = new Pojo();
pojo3.setDetail("晴3");
calendar.set(Calendar.DATE, day+2);
pojo3.setDate(calendar.getTime());
pojo3.setTemperature_max(5);
pojo3.setTemperature_min(-6); list.add(pojo1);
list.add(pojo2);
list.add(pojo3); return list;
}
}
发布服务:
package service; import javax.xml.ws.Endpoint; /**
* 发布服务类
*
*/
public class FaBu { public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:12345/weather", new Impl());
}
}
客户端开发过程:
1.单独创建一个java工程用来存放代码,通过cmd窗口,进入wsimport的src目录
2.输入命令:wsimport -extension -s . http://127.0.0.1:12345/weather?wsdl
生成的代码如下:

3.访问服务类
package client; import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import javax.xml.namespace.QName;
import javax.xml.ws.Service; import service.Impl;
import service.ImplService;
import service.Pojo; /**
* 客户端访问服务类
*
*/
public class Client { public static void main(String[] args) throws Exception {
//创建服务视图
URL wsdlDocumentLocation = new URL("http://127.0.0.1:12345/weather?wsdl");
QName serviceName = new QName("http://service/", "ImplService");
Service service = Service.create(wsdlDocumentLocation, serviceName);
//从服务视图中得到portType对象 ,接口类型
Impl port = service.getPort(Impl.class);
//调用portType方法
List<Pojo> queryWeather = port.queryWeather("郑州");
//解析
for (Pojo pojo : queryWeather) {
System.out.println(pojo.getDetail());
Date date = pojo.getDate().toGregorianCalendar().getTime();
System.out.println(new SimpleDateFormat("yyMMdd").format(date));
System.out.println(pojo.getTemperatureMax());
System.out.println(pojo.getTemperatureMin()); } }
}
jax-ws开发总结的更多相关文章
- nodeJS学习(8)--- WS/...开发 NodeJS 项目-节3 <使用 mongodb 完整实例过程>
使用 mongodb 的小系统 参考:https://my.oschina.net/chenhao901007/blog/312367 1. Robomongo 创建项目的数据库和数据表 参考:htt ...
- nodeJS学习(7)--- WS开发 NodeJS 项目-节2 <安装&设置&启动 mongodb 数据库++遇到的问题>
本文系统 win7 参考:http://lib.csdn.net/article/mongodb/58097 http://www.cnblogs.com/lzrabbit/p/3682510.ht ...
- webservice入门(2)开发ws程序
因为webservice分为服务端和客户端,所以如果要学习的话,那么肯定是包括这两部分的了. 1.开发服务端的webservice: 使用jdk开发ws其实很简单,只是需要一些注解:最重要的是 @We ...
- 转载 WebService 的CXF框架 WS方式Spring开发
WebService 的CXF框架 WS方式Spring开发 1.建项目,导包. 1 <project xmlns="http://maven.apache.org/POM/4.0 ...
- WebService 的CXF框架 WS方式Spring开发
1.建项目,导包. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www ...
- Spring 4 集成Apache CXF开发JAX-RS Web Service
什么是JAX-RS 在JSR-311规范中定义,即Java API for RESTful Web Services,一套Java API,用于开发 RESTful风格的Webservice. 工程概 ...
- iOS开发之 几本书
<object_c 编程之道书> <iOS 7 UI Transition Guide> iOS开发指南:从零基础到App Store上架[国内第一本iOS架构设计图书,涵盖i ...
- Web Service-- 使用 JDK 发布 WS
Web Service,即“Web 服务”,简写为 WS,从字面上理解,它其实就是“基于 Web 的服务”.而服务却是双方的,有服务需求方,就有服务提供方.服务提供方对外发布服务,服务需求方调用服务提 ...
- WebService基础入门 CXF(WS + RS)
一.基本介绍 Web Services是一个软件接口,它描述了一组可以在网络上通过标准化的 XML 消息传递访问的操作.它使用基于 XML 语言的协议来描述要执行的操作或者要与另一个 Web 服务交换 ...
- Java 5 、6、 7中新特性
JDK5新特性(与1.4相比)[转] 1 循环 for (type variable : array){ body} for (type variable : arrayList){body} 而1. ...
随机推荐
- 为什么没有MMU的处理器无法安装操作系统?
所谓的处理器就是计算机的核心运算硬件,现在使用windows操作系统的用户使用的机器之中的处理器多数都是X86内核,而实际之上很多时候我们用户都是会在心目之中把一个处理器和其运行的特定操作系统挂钩,之 ...
- 理解 OpenStack + Ceph (5):OpenStack 与 Ceph 之间的集成 [OpenStack Integration with Ceph]
理解 OpenStack + Ceph 系列文章: (1)安装和部署 (2)Ceph RBD 接口和工具 (3)Ceph 物理和逻辑结构 (4)Ceph 的基础数据结构 (5)Ceph 与 OpenS ...
- [转]OnKeyDown Numeric Validator CLIENT SIDE
本文转自:http://forums.asp.net/t/1211724.aspx?OnKeyDown+Numeric+Validator+CLIENT+SIDE <!DOCTYPE html ...
- leetcode-HouseRobber
这道题比较简单,所以我会介绍的比较粗略: 题目: 有一个小偷想沿着马路上的房子偷东西,每家每户都有一些钱,但这条街上装了监控系统,如果相邻的两户人家都被偷了的话那么就会触发报警器.小偷的目标就是在不触 ...
- [No000018]都在背单词,为啥学霸那么厉害-如何在一天内记200个单词?
- NOIP模拟赛 行走
题目描述 “我有个愿望,我希望走到你身边.” 这是个奇异的世界,世界上的n-1条路联结起来形成一棵树,每条路有一个对应的权值ci. 现在我会给出q组询问或操作. 每次询问我会从一个x点走到y点,初始在 ...
- 【bzoj1828】[Usaco2010 Mar]
Description Input 第1行:两个用空格隔开的整数:N和M * 第2行到N+1行:第i+1行表示一个整数C_i * 第N+2到N+M+1行: 第i+N+1行表示2个整数 A_i和B_i ...
- iOS本地存储-数据库(FMDB)
初识FMDB iOS中原声的SQLite API在进行数据存储的时候,需要使用C语言中的函数,操作比较麻烦,于是就出现了一系列将SQLite封装的库.本文讲解的FMDB就是其中的一个. FMDB PK ...
- Javascript备忘复习笔记2
一.函数与形参 1.函数 function abs(x) { if (x >= 0) { return x; } else { return -x; } } alert(abs(-10)); 2 ...
- 2178 表达式运算Cuties
2178 表达式运算Cuties 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 大师 Master 题解 题目描述 Description 给出一个表达式,其中运算 ...