web service 对外发布一个hello world接口(入门)
1、写一个需要发布的接口
package com.hb; import javax.jws.WebParam;
import javax.jws.WebService; @WebService
public interface IService { public void hello(@WebParam(name="username") String username);
}
备注: 一定要在接口名称上面用 @WebService 注解标示,参数@WebParam(name="username")只是说明在wsdl中指明参数的名字是username
2、对定义接口的实现
package com.hb; import java.util.Date;
import javax.jws.WebParam;
import javax.jws.WebService; @WebService(endpointInterface="com.hb.IService")
public class ServiceImp implements IService{ @Override
public void hello(@WebParam(name = "username") String username) {
System.out.println("hello " + username + " now is " + new Date());
} }
备注: 一定要在接口名称上面用 @WebService 注解标示 ,里面一定要标注它对外的接口,在后面的客户端调用会体现出来。
3、发布对外提供的接口
package com.hb; import javax.xml.ws.Endpoint; public class ServiceMain { public static void main(String[] args) {
String address = "http://172.16.32.72:7777/hb";
Endpoint.publish(address, new ServiceImp());
System.out.println("发布消息成功");
} }
在地址栏中输入 http://172.16.29.89:7777/hb?wsdl,就会出现一系列xml格式的文档,这个就表示发布的成功。
客户端
package com.hb; import java.net.MalformedURLException;
import java.net.URL; import javax.xml.namespace.QName;
import javax.xml.ws.Service; public class Client { /**
* @param args
* @throws MalformedURLException
*/
public static void main(String[] args) throws MalformedURLException {
// TODO Auto-generated method stub
//创建访问wsdl服务地址的url
URL url = new URL("http://172.16.32.72:7777/hb?wsdl");
//通过Qname指明服务的具体信息
/*
* 第一个参数:接口的包名称,反序
* 第二个参数:实现类名+Service
* */
QName qname = new QName("http://hb.com/","ServiceImpService");
//创建服务
Service service = Service.create(url, qname);
//实现接口
IService iservice = service.getPort(IService.class);
//以上服务有问题,依然依赖于IMyServie接口
iservice.hello("huangbiao"); } }
备注:QName qname = new QName("http://hb.com/","ServiceImpService");两个参数分别对应上图中的targetNamespace 和 name。
如果在实现对外提供的接口类中没有@WebService(endpointInterface="com.hb.IService"),则会提示不认识这个接口。
上面全部操作不需要引入任何外部jar包。
web service 对外发布一个hello world接口(入门)的更多相关文章
- 几种远程调用接口协议简单比较和web service(SOAP)与HTTP接口的区别:
什么是web service? 答:soap请求是HTTP POST的一个专用版本,遵循一种特殊的xml消息格式Content-type设置为: text/xml任何数据都可以xml化. ...
- Web Service——CXF发布REST服务
1. 什么是REST REST,英文representational state transfer(表象性状态转变)或者表述性状态转移,REST是web服务的一种架构风格,使用HTTP.URI.XML ...
- ASP.NET Web Service应用发布到IIs怎么做
首先把你写的webservice Publish 到 一个文件夹 D:\MyWebService 下,在IIS下的website里面new一个虚拟目录,别名(Alias)随便输一个(这个别名是用于别的 ...
- 使用JAX-RS创建RESTful Web Service
guice resteasy http://www.cnblogs.com/ydxblog/p/7891224.html http://blog.csdn.net/withiter/article/d ...
- Apache CXF实现Web Service(1)——不借助重量级Web容器和Spring实现一个纯的JAX-WS web service
废话少说,先在Eclipse中新建一个Java Project (可以不是WTP的Dynamic Web Project) 选择Java Project 再看pom.xml 我们使用cxf 3.1.4 ...
- 【Java学习笔记】如何写一个简单的Web Service
本Guide利用Eclipse以及Ant建立一个简单的Web Service,以演示Web Service的基本开发过程: 1.系统条件: Eclipse Java EE IDE for Web De ...
- 构建一个基于 Spring 的 RESTful Web Service
本文详细介绍了基于Spring创建一个“hello world” RESTful web service工程的步骤. 目标 构建一个service,接收如下HTTP GET请求: http://loc ...
- Web Service概念梳理
计算机技术难理解的很多,Web Service 对我来说就是一个很难理解的概念:为了弄清它到底是什么,我花费了两周的时间,总算有了一些收获,参考了不少网上的资料,但有些概念说法不一.我以w3c和 一些 ...
- BizTalk开发系列(二十六) 使用Web Service
Web Service是在构建SOA平台中广泛使用的技术.在BizTalk开发过程中使用SOAP适配器接收和发送 Web Services 请求.业务流程可以发布为 Web Services 并使用外 ...
随机推荐
- 让函数的input、output更"函数化"
前言 我们都知道函数的基本形式为:output f(input),且先按这种形式进行input与output的分析,我们的input与output可以有更好的设计方式,而我们的output是选择使用r ...
- 什么是Uboot
U-Boot的全称是Universal Boot Loader,遵循GPL条款的开放源码项目. U-Boot的作用是系统引导. U-Boot目前不仅仅支持嵌入式Linux系统的引导(对Linux的支持 ...
- hdu1016 Prime Ring Problem(DFS)
Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- management & Actuator
self define indicator https://docs.spring.io/spring-boot/docs/current/reference/html/production-read ...
- 在本地安装oracle-maven库
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging= ...
- Dev Express Report 学习总结(八)Dev Express Reports 常见问题总结
1. 在新建ASP.NET Dev Express Report时的两种方式: A. 右键Add DevExpress Item->New Item->All->从Web Repor ...
- tcp的半连接与完全连接队列(三)源码分析
TCP 协议中的 SYN queue 和 accept queue 处理 若要理解本文意图说明的问题,可能需要以下知识背景: listen 系统调用的 backlog 参数含义,以及与 net.cor ...
- 源码剖析Linux epoll实现机制及Linux上惊群
转载:https://blog.csdn.net/tgxallen/article/details/78086360 看源码是对一个技术认识最直接且最有效的方式了,之前用Linux Epoll做过一个 ...
- [转]Passing data between pages in JQuery Mobile mobile.changePage
本文转自:http://ramkulkarni.com/blog/passing-data-between-pages-in-jquery-mobile/ I am working on a JQue ...
- Cinder Columns
http://www.screencast.com/users/xiangxinyong/folders/Smaug http://www.screencast.com/t/SLqCyOwtBRl