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. ...
随机推荐
- Visual Studio 中的快捷键
VS中常用快捷键 Ctrl+K+D:快速对齐代码 Ctrl+E+D:快速对齐代码 Ctrl+Z:撤销 Ctrl+S:保存 Ctrl+Shift+S:保存所有 Ctrl+J:快速弹出智能提示 Shift ...
- 警惕多iframe下的同名id引起的诡异问题
遇到个诡异bug,虽然bug中套bug,忽略次要bug,其中最诡异最典型的现象是多行window.top.$("#id")取值操作,其中有一行却取不到值.这个着实让我费解.因为用到 ...
- [转]在EntityFramework6中执行SQL语句
本文转自:http://www.cnblogs.com/wujingtao/p/5412329.html 在上一节中我介绍了如何使用EF6对数据库实现CRDU以及事务,我们没有写一句SQL就完成了所有 ...
- [转]在ASP.NET开发中容易忽略的2个小问题 Cookie乱码存取异常 和 iframe弹框的login跳转
本文转自:http://www.cnblogs.com/outtamyhead/p/3642729.html 本文地址:http://www.cnblogs.com/outtamyhead/p/364 ...
- Machine Learning Algorithms Study Notes(3)--Learning Theory
Machine Learning Algorithms Study Notes 高雪松 @雪松Cedro Microsoft MVP 本系列文章是Andrew Ng 在斯坦福的机器学习课程 CS 22 ...
- POJ 3449 Geometric Shapes --计算几何,线段相交
题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...
- POJ1062昂贵的聘礼[最短路建模]
昂贵的聘礼 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45892 Accepted: 13614 Descripti ...
- 记录mysql的具体操作明细
在MySQL中使用init-connect与binlog来实现用户操作追踪记录 2014-07-28 20:55:38 分类: MySQL 前言:测试环境莫名其妙有几条重要数据被删除了,由于在binl ...
- Eclipse cpp 开发 include路径
- 审核被拒(后台定位,autio,voip,发表朋友圈)
APP上线审核被拒那些事(一) 2.3 - Apps that do not perform as advertised by the developer will be rejected 2.3 D ...