webservice笔记(一)
来源:互联网 发布:龙腾世纪捏脸数据 编辑:程序博客网 时间:2024/05/27 09:45
webService简写为ws,也就是web服务,是基于HTTP协议的,通过HTTP进行传输的
使用 JDK 发布 WS
package com.cxf.a;import javax.jws.WebService;//@WebService说明该接口是一个 WS 接口(称为“Endpoint,端点”),其中的方法是 WS 方法(称为“Operation,操作”)@WebServicepublic interface HelloService { public String say(String name);}
package com.cxf.a;import javax.jws.WebService;@WebService( serviceName = "HelloService", portName = "HelloServicePort", endpointInterface = "com.cxf.a.HelloService")public class HelloServiceImpl implements HelloService { public String say(String name) { return "hello " + name; }}
package com.cxf.a;import javax.xml.ws.Endpoint;public class Server { public static void main(String[] args) { String address = "http://localhost:8080/ws/soap/hello"; HelloService helloService = new HelloServiceImpl(); Endpoint.publish(address, helloService); System.out.println("ws is published"); }}
引入依赖
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http-jetty</artifactId> <version>2.4.6</version></dependency>
只需要以上三个类,即可发布一个服务(使用jetty作为服务容器,故,必须引入jetty的相关jar)
http://localhost:8080/ws/soap/hello?wsdl
http://localhost:8080/ws/soap/hello/say/arg0/yuruixin
打开上述网址,若出现xml以下内容即为发布成功
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:sayResponse xmlns:ns2="http://a.cxf.com/"> <return>hello yuruixin</return> </ns2:sayResponse> </soap:Body></soap:Envelope>
JAX-WS 有一个官方实现,就是上面提到的 JAX-WS RI,它是 Oracle 公司提供的实现,而 Apache 旗下的 Axis 与 CXF 也同样实现了该规范。Axis 相对而言更加老牌一些,而 CXF 的前世就是 XFire,它是一款著名的 WS 框架,擅长与 Spring 集成
从本质上讲,JAX-WS 是基于 SOAP 的,而 SOAP 的全称是 Simple Object Access Protocol(简单对象访问协议)
本系列笔记学习对象为开源中国https://my.oschina.net/huangyong/blog
0 0
- Webservice笔记(一)
- webservice笔记(一)
- WebService学习笔记(一)
- WebService笔记(一):本质
- webService开发笔记(一)
- webservice学习笔记(一)
- Apache CXF Webservice学习笔记(一)
- webservice的学习笔记(一)
- WebService学习笔记系列(一)
- Webservice学习笔记(一)简介
- WebService 学习笔记一
- webservice 入门笔记一
- webservice笔记一
- [WebService]WebService初级教程(一)
- axis2 webservice学习笔记一
- 基于Axis 1.4 部署WebService 笔记(一)
- WebService开发笔记(一)-- 利用cxf开发WebService竟然如此简单
- java学习笔记之webservice(一)-入门实例,自定义webservice服务
- Java 获取时间毫秒数并格式化
- 关于移动端1px线处理和伪类组合使用
- kfree_skb,dev_kfree_skb,__kfree_skb,kfree比较分析详解
- JAXB生成xml
- annotationProcessor实战,了解ButterKinfe过程
- webservice笔记(一)
- Nohttp的使用(二)封装
- thinkphp 返回json 数据
- 在adapter中对item的某个控件点击,并在点击事件中对其他item控件进行设置
- boost::format给std::string插上翅膀
- rsync 介绍
- zookeeper windows单机模式和伪集群模式
- 如何清除Android项目中的多余资源
- Error:java.lang.RuntimeException: Some file crunching failed, see logs for details