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 ...
随机推荐
- TypeScript学习笔记(六):泛型
认识泛型 TypeScript也实现了类型于C#和Java的泛型以实现类型的参数化,我们先看一个需求: function identity(arg: any): any { return arg; } ...
- 调用DEDE日期时间格式整理大全
dedecms 日期时间格式大全,大家可以根据需要选择.DEDECMS利用strftime()函数格式化时间的所有参数详解,包括年份日期进制.小时格式等,大家收藏吧,呵. 日期时间格式 (利用strf ...
- 8086、80x86(IA-32)、64(IA-64)位CPU发展
众所周知,CPU(中央处理单元)是计算机的核心部分,CPU在单位时间内能一次处理的二进制数的位数叫字长,从386.486直到奔腾系列的CPU都是32位,大多数情况32位计算已经能满足现阶段人们的需要. ...
- 利用微软Speech SDK 5.1开发语音识别系统主要步骤
利用微软Speech SDK 5.1开发语音识别系统主要步骤 2009-09-17 10:21:09| 分类: 知识点滴|字号 订阅 微软语音识别分两种模式:文本识别模式和命令识别模式.此两种模式的 ...
- 《JavaScript高级程序设计》 读书笔记(三)
操作符 递增和递减操作符 var num1 = 2; var num2 = 20; var num3 = --num1 + num2; // 等于 21 var num4 = num1 + num2; ...
- 一次线上OOM故障排查经过
转贴:http://my.oschina.net/flashsword/blog/205266 本文是一次线上OOM故障排查的经过,内容比较基础但是真实,主要是记录一下,没有OOM排查经验的同学也可以 ...
- PostgreSQL的 initdb 源代码分析之九
继续:下面的是定义信号处理函数. /* * now we are starting to do real work, trap signals so we can clean up */ /* som ...
- 关于2000W数据
前几天在博客园首页看到这个2000W数据的消息,刚好这个学期正在SQL入门,加上好奇心的驱使,把这个下载下来. 一个是600多M的CSV文件,还有一个是1.7G的SQL Server的备份文件,解压后 ...
- C++ struct与class
1.相对于C中struct,C++做了很大的扩充.基本上和class 差不多.只有一些细节上的差别. 2.对于成员的默认访问权限,class是private,struct是public.需要注意的是, ...
- cdoj 1256 昊昊爱运动 预处理/前缀和
昊昊爱运动 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1256 Descr ...