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接口(入门)的更多相关文章

  1. 几种远程调用接口协议简单比较和web service(SOAP)与HTTP接口的区别:

    什么是web service?       答:soap请求是HTTP POST的一个专用版本,遵循一种特殊的xml消息格式Content-type设置为: text/xml任何数据都可以xml化. ...

  2. Web Service——CXF发布REST服务

    1. 什么是REST REST,英文representational state transfer(表象性状态转变)或者表述性状态转移,REST是web服务的一种架构风格,使用HTTP.URI.XML ...

  3. ASP.NET Web Service应用发布到IIs怎么做

    首先把你写的webservice Publish 到 一个文件夹 D:\MyWebService 下,在IIS下的website里面new一个虚拟目录,别名(Alias)随便输一个(这个别名是用于别的 ...

  4. 使用JAX-RS创建RESTful Web Service

    guice resteasy http://www.cnblogs.com/ydxblog/p/7891224.html http://blog.csdn.net/withiter/article/d ...

  5. 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 ...

  6. 【Java学习笔记】如何写一个简单的Web Service

    本Guide利用Eclipse以及Ant建立一个简单的Web Service,以演示Web Service的基本开发过程: 1.系统条件: Eclipse Java EE IDE for Web De ...

  7. 构建一个基于 Spring 的 RESTful Web Service

    本文详细介绍了基于Spring创建一个“hello world” RESTful web service工程的步骤. 目标 构建一个service,接收如下HTTP GET请求: http://loc ...

  8. Web Service概念梳理

    计算机技术难理解的很多,Web Service 对我来说就是一个很难理解的概念:为了弄清它到底是什么,我花费了两周的时间,总算有了一些收获,参考了不少网上的资料,但有些概念说法不一.我以w3c和 一些 ...

  9. BizTalk开发系列(二十六) 使用Web Service

    Web Service是在构建SOA平台中广泛使用的技术.在BizTalk开发过程中使用SOAP适配器接收和发送 Web Services 请求.业务流程可以发布为 Web Services 并使用外 ...

随机推荐

  1. sharepoint_study_8

    描述:如何删除webPart无效文件? 图示: 有时候webpart的部署包虽然删除了,但是它的文件依然会留在这个类别中,怎样删除这些无效的文件呢? 解决: 在网站设置中打开web部件,里面列出了网站 ...

  2. 毕业设计 python opencv实现车牌识别 颜色判断

    主要代码参考https://blog.csdn.net/wzh191920/article/details/79589506 GitHub:https://github.com/yinghualuow ...

  3. Experimental Educational Round: VolBIT Formulas Blitz J

    Description IT City company developing computer games invented a new way to reward its employees. Af ...

  4. Ansible自动化运维工具

    ansible软件介绍 python语言是运维人员必会的语言!  ansible是一个基于Python开发的自动化运维工具!(saltstack)  其功能实现基于SSH远程连接服务!  ans ...

  5. js中url有中文的转码方法

    转载:https://www.cnblogs.com/chiangfai/p/6073000.html

  6. 对称加密中的ECB模式&CBC模式

    ECB模式: CBC模式: 所有的迭代模式:

  7. thinkPHP5.0验证器自定义验证规则

    自定义验证规则 protected $rule = [ 'views' => 'require|number|checkviews:0',//checkviews为自定义验证规则,0是传过去的规 ...

  8. java——链表、链表栈 LinkedListStack、链表队列 LinkedListQueue

    LikedList: package Date_pacage; public class LinkedList<E> { public static void main(String[] ...

  9. JavaSE---内部类

    1.概述 1.1 内部类:一个类定义在其他类的内部,这个类被称为内部类: 1.1.1 内部类可以放在外部类的任何位置,方法中也可以(称为局部内部类): 1.1.2 一般将内部类作为 成员内部类 使用 ...

  10. (转)AIX下的MPIO、RDAC、SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系)

    AIX下的MPIO.RDAC.SDDPCM多路径软件操作 (AIX下的MPIO,查看AIX下hdisk与盘柜卷lun的对应关系) 原文:http://blog.163.com/huangbao_007 ...