【简述】

查询三天的天气信息(天气概况、日期、温度),测试jaxws是否支持自定义pojo发布服务。

【开发过程】

服务端:

1.自定义pojo(天气概况、日期、温度)

2.开发SEI接口及实现类

3.发布服务

客户端:(采用service类标准方法调用webService)

1.根据wsdl说明书生成客户端调用代码。

2.将生成代码拷贝到工程中,编写客户端类。

【服务端工程截图】

【WeatherModel.java】

package com.Higgin.ws.pojo;
import java.util.Date; public class WeatherModel { //天气概况
private String detail; //日期
private Date date; //最高温度
private int temperature_max; //最低温度
private int temperature_min;
//忽略get/set方法...........
}

【WeatherInterface.java】

package com.Higgin.ws.service;

import java.util.List;
import com.Higgin.ws.pojo.WeatherModel; public interface WeatherInterface {
public List<WeatherModel> queryWeatheer(String cityName);
}

【WeatherInterfaceImpl.java】

package com.Higgin.ws.service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import javax.jws.WebService; import com.Higgin.ws.pojo.WeatherModel; @WebService
public class WeatherInterfaceImpl implements WeatherInterface{ @Override
public List<WeatherModel> queryWeatheer(String cityName) { //构造三天天气
List<WeatherModel> list =new ArrayList<WeatherModel>();
Calendar calendar=Calendar.getInstance();
int day=calendar.get(Calendar.DATE); WeatherModel weatherModel_1=new WeatherModel();
weatherModel_1.setDetail("晴天");
weatherModel_1.setDate(new Date());
weatherModel_1.setTemperature_max(10);
weatherModel_1.setTemperature_min(-10); WeatherModel weatherModel_2=new WeatherModel();
weatherModel_2.setDetail("阴天");
calendar.set(Calendar.DATE, day+1);
weatherModel_2.setDate(calendar.getTime());
weatherModel_2.setTemperature_max(6);
weatherModel_2.setTemperature_min(-2); WeatherModel weatherModel_3=new WeatherModel();
weatherModel_3.setDetail("晴天");
calendar.set(Calendar.DATE, day+2);
weatherModel_3.setDate(calendar.getTime());
weatherModel_3.setTemperature_max(30);
weatherModel_3.setTemperature_min(3); list.add(weatherModel_1);
list.add(weatherModel_2);
list.add(weatherModel_3);
return list;
} }

【WeatherServer.java】

package com.Higgin.ws.service;

import javax.xml.ws.Endpoint;

public class WeatherServer {
public static void main(String[] args) {
Endpoint.publish("http://127.0.0.1:12345/weather", new WeatherInterfaceImpl());
}
}

【客户端工程截图】

已经使用Wsimport生成了相应的客户端代码

【WeatherClient.java】

package com.higgin.ws.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 com.higgin.ws.service.WeatherInterfaceImpl;
import com.higgin.ws.service.WeatherModel; public class WeatherClient { public static void main(String[] args) throws MalformedURLException {
//使用说明书
URL wsdlDocumentLocation =new URL("http://127.0.0.1:12345/weather?wsdl"); QName serviceName=new QName("http://service.ws.Higgin.com/", "WeatherInterfaceImplService"); //创建服务视图
Service service=Service.create(wsdlDocumentLocation,serviceName); //创建portType对象
WeatherInterfaceImpl weatherInterfaceImpl=service.getPort(WeatherInterfaceImpl.class); //调用WeatherInterfaceImpl方法
List<WeatherModel> list=weatherInterfaceImpl.queryWeatheer("杭州"); for(WeatherModel weatherModel:list){
System.out.println(weatherModel.getDetail());
Date date=weatherModel.getDate().toGregorianCalendar().getTime();
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(date));
System.out.println(weatherModel.getTemperatureMax());
System.out.println(weatherModel.getTemperatureMin());
} } }

【运行结果】

10_Jaxws使用自定义pojo发布服务的更多相关文章

  1. 自定义及发布一个webservice服务

    自定义及发布一个webservice服务    - 声明 某个业务服务为webservice服务       通过@webservice 注解来声明    - 发布webservice服务       ...

  2. Dubbo2.7源码分析-如何发布服务

    Dubbo的服务发布逻辑是比较复杂的,我还是以Dubbo自带的示例讲解,这样更方便和容易理解. Provider配置如下: <?xml version="1.0" encod ...

  3. ArcGIS 将自定义工具发布到ArcGIS Server,作为Geoprocessing Service

    新建自定义工具过程可参考上一篇博客:http://www.cnblogs.com/oceanking/p/3933681.html 1.执行自定义工具.此步骤不可省略 打开ArcCatalog,双击自 ...

  4. ServiceStack.Redis订阅发布服务的调用(Z)

      1.Redis订阅发布介绍Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式.发布者和订阅者之间使用频 ...

  5. ArcGIS Server开发教程系列(2)配置ARCMAP和ARCCatalog发布服务

    1.       Arc catalog的配置 打开catalog,如图新增刚刚创建的server 1. Use GIS services: 用户身份连接 使用此种连接,可以浏览.使用站点内发布的所有 ...

  6. ServiceStack.Redis订阅发布服务的调用

    1.Redis订阅发布介绍 Redis订阅发布是一种消息通信模式:发布者(publisher)发送消息,订阅者(Subscriber)接受消息.类似于设计模式中的观察者模式. 发布者和订阅者之间使用频 ...

  7. ArcGIS发布服务时缓存切片设置

    [文件]>[共享]>[服务]>[覆盖原有服务]或[创建新服务] 设置好相关参数后,会弹出"服务编辑框": 进入"缓存" 1."绘制此 ...

  8. 使用expect脚本语言写一键发布服务(代码发布、所有服务重启)

    互联网服务有很多台服务,但是在上线的时候需要将这些服务版本都更新与个个都重启,下面的脚本语言,就是一键发布服务~ 1.在/home/weihu/deploy/ 目录下建下publish .publis ...

  9. PHPRPC jsp发布服务

    PHPRPC是面向服务的高性能远程过程调用协议.PHPRPC for java 是此协议的一种实现,详细请到官方看PHPRPC的介绍 ,以其它rpc协议的性能对比请:Java.PHPRPC.Hessi ...

随机推荐

  1. 【Stage3D学习笔记续】山寨Starling(十一):Touch事件体系

    我们的山寨Starling版本将会在这里停止更新了,主要还是由于时间比较有限,而且我们的山寨版本也很好的完成了他的任务“了解Starling的核心渲染”,接下来的Starling解析我们将会直接阅读S ...

  2. Android开发之有效获取状态栏(StatusBar)高度

    获取状态栏高度 一.传统方式:有时获取为0,解决方法看  二 1 2 3 4 代码 Rect frame = new Rect(); getWindow().getDecorView().getWin ...

  3. 【转】从开发者的角度看待各移动平台 ios/android/wp7/win8ost title

    T_T 这伪技术博客都快给写成Tron的读书笔记专栏了,这样可不行欸~ 如今正是移动平台的战国时期,厌烦了去讨论移动平台的未来,也无意于在HTML5和Native App之间纠结.本文只从开发者纯技术 ...

  4. Session笔记

    一.Session机制 session机制採用的是在server端保持 HTTP 状态信息的方案 . server使用一种类似于散列表的结构(也可能就是使用散列表)来保存信息. 当程序须要为某个cli ...

  5. Python 对新浪微博的博文元素 (Word, Screen Name)的频率分析

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-9 @author: guaguastd @name: we ...

  6. Jenkins(二)

    官网:https://wiki.jenkins-ci.org/display/JENKINS/Meet+Jenkins 我的这篇文章不过简单的依据上文,介绍Jenkins提供了哪些功能.详细大家还是要 ...

  7. 使用百度地图结合GPS进行定位

    本文在上文基础上加入GPS定位功能,实现实时定位,代码如下: Activity: package com.home; import android.app.Activity; import andro ...

  8. [RxJS] just, return

    Sometime, we migth just want to return a object which wrap into Observable. You can use 'just' or  ' ...

  9. AIR 移动设备上的存储控制

    File.documentsDirectory, File.userDirectory, File.desktopDirectory 等.可以保存大的数据,如图片,视屏,和临时文件.访问这些文件的全选 ...

  10. percona监控模板图形解释

    http://blog.itpub.net/28916011/viewspace-1971933/ percona监控mysql的几张图形解释     最近,我仔细研究了一下percona监控mysq ...