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 ...
随机推荐
- CodeForces 705A Hulk (水题)
题意:输入一个 n,让你输出一行字符串. 析:很水题,只要判定奇偶性,输出就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,10240 ...
- window 下cygwin开启了后来又关闭了
特征: ssh localhost 出现port 27 拒绝访问等 系统日志记录信息: 事件 ID ( 0 )的描述(在资源( sshd )中)无法找到.本地计算机可能没有必要的注册信息或消息 DLL ...
- django控制admin的model显示列表
class goods(models.Model): name = models.CharField(max_length=300) price = models.IntegerField ...
- 数据访问层DAL(数据库访问抽象类DataProvider)
晒晒数据访问层DAL,看看你的项目数据访问层使用的是什么形式,数据访问性能比较 采用什么样的数据访问形式是软件编码很重要的一个环节,良好的数据访问形式不仅能够提搞代码的执行效率,协作能力,更重要的是对 ...
- socket.io+angular.js+express.js做个聊天应用(一)
node,express开发环境等安装如果已经搞好了. justhacker@justhacker-ThinkPad-Edge-E440:~/projects/nodejs$ express -e c ...
- C++ CheckMenuItem
菜单单选 关键点 CMenu::GetMenuState UINT GetMenuState( UINT nID, UINT nFlags ) const; MF_CHECKED MF_DISABLE ...
- 第十七章,txt文件的写入和读取数据结合练习(C++)
#include <iostream> #include <fstream> int main(int argc, char** argv) { std::string str ...
- Android 开发之旅:深入分析布局文件&又是“Hello World!”
http://www.cnblogs.com/skynet/archive/2010/05/20/1740277.html 引言 上篇可以说是一个分水岭,它标志着我们从Android应用程序理论进入实 ...
- SSL连接建立过程分析(1)
Https协议:SSL建立过程分析 web訪问的两种方式: http协议,我们普通情况下是通过它訪问web,由于它不要求太多的安全机制,使用起来也简单,非常多web网站也仅仅支持这样的方式下的訪问. ...
- SSH框架之Struts(2)——Struts的执行流程之配置文件
上篇我们大致了解了一下採用了Struts框架的web页面运行流程. 接下来的几篇我们通过Struts的源代码来学习一下Struts的内部原理. 当server启动的时候.server会依据配置文件初始 ...