CXF(2.7.10) - A simple JAX-WS service
1. 下载 apache-cxf-x.x.x.zip,在工程导入依赖的 jar 包。也可以基于 Maven 构建工程。
2. 定义服务接口。
package com.huey.demo.ws; import javax.jws.WebParam;
import javax.jws.WebService; @WebService
public interface HelloService { public String sayHello(@WebParam(name="who") String who); }
3. 实现服务接口。
package com.huey.demo.ws.impl; import javax.jws.WebParam;
import javax.jws.WebService; import com.huey.demo.ws.HelloService; @WebService(name="helloService", endpointInterface="com.huey.demo.ws.HelloService")
public class HelloServiceImpl implements HelloService { public String sayHello(@WebParam(name="who") String who) {
String helloMsg = "Hello, " + who + "!";
return helloMsg;
} }
4. 发布服务。
package com.huey.demo.main; import javax.xml.ws.Endpoint; import com.huey.demo.ws.HelloService;
import com.huey.demo.ws.impl.HelloServiceImpl; public class Server { public void publishWebService() {
HelloService helloService = new HelloServiceImpl();
String address = "http://localhost:9090/hello";
Endpoint.publish(address, helloService);
} public static void main(String[] args) {
try {
new Server().publishWebService(); System.out.println("Server Ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server Existing...");
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("Ending...");
}
} }
5. 在浏览器键入 http://localhost:9090/hello?wsdl,验证服务是否发布成功。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://impl.ws.demo.huey.com/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns2="http://schemas.xmlsoap.org/soap/http" xmlns:ns1="http://ws.demo.huey.com/" name="HelloServiceImplService" targetNamespace="http://impl.ws.demo.huey.com/">
<wsdl:import namespace="http://ws.demo.huey.com/" location="http://localhost:9090/hello?wsdl=HelloService.wsdl"/>
<wsdl:binding name="HelloServiceImplServiceSoapBinding" type="ns1:HelloService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloServiceImplService">
<wsdl:port name="helloServicePort" binding="tns:HelloServiceImplServiceSoapBinding">
<soap:address location="http://localhost:9090/hello"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
6. 访问服务。
package com.huey.demo.main;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import com.huey.demo.ws.HelloService;
public class Client {
public static void main(String[] args) {
try {
System.out.println("Starting Client...");
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(HelloService.class);
factory.setAddress("http://localhost:9090/hello");
HelloService helloService = (HelloService) factory.create();
String helloMsg = helloService.sayHello("Huey");
System.out.println(helloMsg);
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("Ending...");
}
}
}
7. SoupUI 测试。

CXF(2.7.10) - A simple JAX-WS service的更多相关文章
- CXF(2.7.10) - RESTful Services, JSON Support
在 CXF(2.7.10) - RESTful Services 介绍了 REST 风格的 WebService 服务,数据传输是基于 XML 格式的.如果要基于 JSON 格式传输数据,仅需要将注解 ...
- Create a simple REST web service with Python--转载
今日尝试用python建立一个restful服务. 原文地址:http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-r ...
- CXF(2.7.10) - Writing a service with Spring
1. 定义服务接口. package com.huey.demo.ws; import javax.jws.WebParam; import javax.jws.WebService; @WebSer ...
- CXF(2.7.10) - RESTful Services
1. 定义 JavaBean.注意 @XmlRootElement 注解,作用是将 JavaBean 映射成 XML 元素. package com.huey.demo.bean; import ja ...
- CXF(2.7.10) - WSDL2Java generated Client
以调用 http://www.webxml.com.cn/ 提供的 IpAddressSearchWebService 服务为例. 1. 使用 wsdl2java 工具,根据 wsdl 生成 JAX- ...
- CXF实战之在Tomcat中公布Web Service(二)
服务接口及实现类请參考WebService框架CXF实战(一) 创建Maven Web项目,在pom.xml中加入CXF和Spring Web的引用,因为CXFServlet须要Spring Web的 ...
- Win7 ArcGIS 10.5 安装错误 A service pack is required on this operatiing system
前段时间有朋友反馈在Win7专业版下安装ArcGIS 10.5, 无法安装,弹出错误: A service pack is required on this operatiing system,如图: ...
- 转载 WebService 的CXF框架 WS方式Spring开发
WebService 的CXF框架 WS方式Spring开发 1.建项目,导包. 1 <project xmlns="http://maven.apache.org/POM/4.0 ...
- WebService 的CXF框架 WS独立服务之HelloWorld
WebService:不同系统不同语言的数据交互, CXF主要分为两种服务方式: 1 )JAX-WS:传输数据, xml格式,基于SOAP协议(规范:规定了xml传递数据的编码规范) ; 2 )JAX ...
随机推荐
- oracle对序列的操作
select t.*, t.rowid from tbl_type t order by t.id desc Select SEQ_TBL_TYPE_ID.NextVal From Dual; ; ; ...
- PROCESS_YIELD()宏使用及过程分析<contiki学习笔记之八>
好吧,昨晚上研究了switch()的底层实现原理--发现它并不是一般C语言教科书上那样所言,当然,这对于本身就非常熟悉汇编的同学来说,是小菜一碟.世界上,很多事情是巧合与必然的结合体,没有无缘无故的爱 ...
- 【转】python的小知识
1. 如何反序访问一个序列(how do I iterate over a sequence in reverse order) 如果序列是list,则使用list.reverse()即可将序列反序. ...
- esxi 5.1 由于断电错误无法启动 报错 bank5 invalid configuration
由于着急,处理过程中也没有截图,这里简单的描写叙述下整个过程吧. IBM pcserver x3850 可能是机器太热的原因,中午无故掉电,导致esxi无法正常启动 启动时报错 bank5 inval ...
- spring中的ResourceBundleMessageSource
1 首先创建两个资源文件 messages_en_US.properties customer.name=Yong Mook Kim, age : {0}, URL : {1} messages ...
- 批量导出表数据到CSV文件
需求:把oracle数据库中符合条件的N多表,导出成csv文本文件,并以表名.csv为文件名存放. 实现:通过存储过程中UTL_FILE函数来实现.导出的csv文件放入提前创建好的directory中 ...
- fedora 20 注销
当系统只有一个用户和只有一个桌面环境时,Fedora 20将不会显示Log Out菜单. 如果你确实需要logout,可以通过执行gnome-session-quit命令来logout. 如果你确实需 ...
- mysql 日期函数格式
mysql中的from_unixtime函数的format表达式字段描述: %M 月名字(January……December) %W 星期名字(Sunday……Saturday) %D 有英语前缀的 ...
- Redis 有序集合(sorted set)
Redis 有序集合和集合一样也是string类型元素的集合,且不允许重复的成员. 不同的是每个元素都会关联一个double类型的分数.redis正是通过分数来为集合中的成员进行从小到大的排序. 有序 ...
- 解决Kscope中文乱码问题
当安装Kscope完成后,然后配置以下三个路径:Cscope path:/usr/bin/cscopeCtags path:/usr/bin/ctagsDot path:/usr/bin/dot 对于 ...