WebService学习笔记系列(四)
来源:互联网 发布:php空心菱形原理 编辑:程序博客网 时间:2024/05/08 00:36
今天主要来看看服务端的编写及发布。
服务端的编写主要包括三个步骤:
1.编写一个接口,即SEI(server endpoint interface)
2.编写接口的实现类,即SIB (server implements bean)
3.发布服务
在接口和实现类上都要用注解说明情况。
接口
@WebServicepublic interface IMyServer { public int add(int a,int b); public int minus(int a,int b);}
实现类:
@WebService(endpointInterface="server.lenve.IMyServer")public class MyServerImpl implements IMyServer { @Override public int add(int a, int b) { System.out.println(a+"+"+b+"="+(a+b)); return a+b; } @Override public int minus(int a, int b) { System.out.println(a+"-"+b+"="+(a-b)); return a-b; }}
发布:
public class PublishMyServer { public static void main(String[] args) { String address = "http://localhost:9999/ns"; Endpoint.publish(address, new MyServerImpl()); }}
通过wsimport拿到相关类,
将这些类拷贝到客户端,然后在客户端调用:
客户端调用:
public class MyFirstClient { public static void main(String[] args) { IMyServer myServerImpl = new MyServerImplService() .getMyServerImplPort(); System.out.println(myServerImpl.add(3, 4)+"------"); }}
当我们把网上的东西导成Java文件后,有些参数变得不是那么讨人喜欢,比如,所有函数的参数命名均为arg0,arg1….,这样让我们很难识别,该怎么办呢?
那就是在服务端的接口中来做一个简单处理:
在每个参数前加上@WebParam注解,我们再尝试在方法前加上@WebResult注解,看代码:
@WebServicepublic interface IMyServer { @WebResult(name="addResult") public int add(@WebParam(name="a")int a,@WebParam(name="b")int b); public int minus(int a,int b);}
add方法添加了注解,minus方法没有添加注解,我们看看生成的代码有什么不同?
参数名变了吧?再看看返回有什么不同:
0 0
- WebService学习笔记系列(四)
- WebService学习笔记系列(一)
- WebService学习笔记系列(二)
- WebService学习笔记系列(三)
- OpenCV学习笔记系列(四)
- OllyDbg破解系列学习笔记(四)
- spring4.x系列学习笔记(四)
- C++学习笔记系列四
- 机器学习系列笔记(四)
- java学习笔记之webservice(四)--用Myeclipse在web项目中发布WebService
- J2EE系列之SpringMVC学习笔记(四)--SpringMVC控制器
- python学习笔记(四)——系列数据类型
- UML/ROSE学习笔记系列四:图
- Android Fragment系列学习笔记之四
- 【学习笔记】系列四:Linux安装PCRE
- game design原理系列学习笔记(四)
- FreeRTOS系列学习笔记四---task
- WebServices学习笔记(四)使用services.xml文件发布WebService
- 六步优化你的 Ubuntu 14.04
- leetcode 165 Compare Version Numbers
- PHP汉字转换为拼音字头原理
- 【转】C++默认构造函数
- MySQL学习笔记_4_MySQL创建数据表(下)
- WebService学习笔记系列(四)
- 网上生意应该注意的
- onSaveInstanceState和onRestoreInstanceState()
- color animation特效制作
- 分页封装
- 多线程Future之Guava ListenableFuture
- 常用的正则表达式(合集)
- java-InputStreamReader 和 OutputStreamWriter类用法简介,及演示。
- 如何生成随机数(上)