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. ...
随机推荐
- seq
Linux 中seq 命令的用法 用于产生从某个数到另外一个数之间的所有整数 用法: seq [选项]... 尾数 或:seq [选项]... 首数 尾数 或:seq [选项]... 首数 增量 尾数 ...
- CSS Sprite雪碧图应用
在写网页过程中,会遇到这种需要使用多个小图标: 如上图中的「女装」文字左边的图标.容易想到的解决方法是为每张图片加入<img>标签,但这样做会增加HTTP请求数量,影响网站加载速度.比这更 ...
- Seajs是什么及sea.js 由来,特点以及优势
Seajs是什么及sea.js 由来,特点以及优势 这篇文章主要介绍了Seajs的相关知识和和学习心得,适合刚接触SeaJS的同学,需要的朋友可以参考下,有更好的新手教程或文档,欢迎推荐.分享 1 ...
- 转:大气炫酷焦点轮播图js特效
使用方法 Step 1. 在html的标签内引入相关文件 <script type="text/javascript" src="js/myfocus-2.0.0. ...
- Asp.Net MVC中DropDownListFor的用法(转)
2016.03.04 扩展:如果 view中传入的是List<T>类型 怎么使用 DropList 既然是List<T> 那么我转化成 T List<T>的第一个 ...
- childNodes的兼容性问题
元素.childNodes:只读 属性 子节点列表集合 标准浏览器下:包含文本和元素类型节点,也会包含非法嵌套的子节点 非标准浏览器下:只包含元素类型节点,ie7下不会包含非法嵌套的子节点 child ...
- 让树莓派开机发送自己的ip到邮箱
一.代码如下: sendIpMail.py #-*-coding=utf-8-*- import socket import fcntl import struct from email import ...
- web框架学习列表
转载自鲁塔弗的博客,原文网址:http://lutaf.com/148.htm web framework层出不穷,特别是ruby/python,各有10+个,php/java也是一大堆 根据我自己的 ...
- css实现省略号
样式: {width: 160px; overflow: hidden; text-overflow:ellipsis; white-space: nowrap;} 说明: white-space: ...
- PL/SQL Developer 11 64bit 安装和配置
安装后, 1. 解压 instant client 到plsql developer 的安装目录 注意, 此版本只支持 instantclient_11_x, 不支持 instantclient ...