1、开发环境:
cxf-2.3.3.jar
MyEclipse6.6
JDK1.5
Tomcat-5.5.27
2、 理论联系实际,现用一个 Demo来说明事更加直观。
新建一个WebService Project,导入cxf常用.jar包。
第一步:新建一个webservice接口, 接口IHelloService.java
package demo.cxf.server;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
//通过注解@WebService申明为webservice接口
public interface IHelloService {
//@WebParam给参数命名,提高可代码可读性
public String sayHello(@WebParam(name="text")String text);
}
第二步,实现WebService接口 实现类HelloServiceImpl.java
package demo.cxf.server;
import javax.jws.WebService;
@WebService(endpointInterface="demo.cxf.server.IHelloService",serviceName="helloService")
public class IHelloServiceImpl implements IHelloService {
public String sayHello(String text) {
return "Hello ".concat(text);
}
}
第三步,创建服务端
public class DeployServer {
private DeployServer(){
IHelloService helloService = new HelloServiceImpl();
//创建WebService服务工厂
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
//注册WebService接口
factory.setServiceClass(IHelloService.class);
//发布接口
factory.setAddress("http://localhost:9000/HelloService");
factory.setServiceBean(helloService);
//创建WebService
factory.create();
};
public static void main(String[] args) throws InterruptedException{
//启动服务端
new DeployServer();
System.out.println("Server ready...");
//休眠一分钟,便于测试
Thread.sleep(1000*60);
System.out.println("Server exit...");
System.exit(0);
}
}
第四步,创建客户端
public class Client {
private Client(){};
public static void main(String[] args){
//创建WebService客户端代理工厂
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
//注册WebService接口
factory.setServiceClass(IHelloService.class);
//设置WebService地址
factory.setAddress("http://localhost:8080/HelloService");
IHelloService iHelloService = (IHelloService)factory.create();
System.out.println("invoke webservice...");
System.out.println("message context is:"+iHelloService.sayHi("
Josen"));
System.exit(0);
}
}
现在是万事俱备,只欠测试了
首先,运行服务端程序
其次,打开浏览器,在地址栏中输入http://localhost:8080/HelloService?wsdl(因为cxf自带了一个jetty服务器),查看接口是否发布成功,如里浏览器页面显示一些XML,证明接口发布成功。
最后,运行客户端程序,就可以看到效果了。
分享到:
相关推荐
springboot+cxf实现webservice示例 <groupId>org.springframework.boot <artifactId>spring-boot-starter <groupId>org.springframework.boot <artifactId>spring-boot-starter-web <!-- CXF ...
借鉴网上例子,弄了一个SpringBoot开发WebService之CXF示例。
现在主流的webService框架,一个是axis2,一个是cxf,本资源是基于cxf框架的简单例子
webservice示例 springmvc+maven+cxf发布webservice 博客地址 http://blog.csdn.net/joe_storm/article/details/78839150
webservice cxf示例工程集成spring,包含所有jar包和测试类。使用的是myeclipse8.5
readme下为开发文档。 1.集成 spring 2.集成 WSS4J 3.mtom 功能示例 4.基本数据类型service接口 示例 5.复杂数据类型service接口 示例
CXF构建WebService示例,具有一定的参考价值,可供学习
1. 发布和调用WebService: 使用CXF2.4(http://cxf.apache.org)和spring 2. 调用安全性: 使用简单的USERNAME_TOKEN 3. 服务程序中取得调用者身份 ------------------------- 接口 ------------------------- intf....
CXF WebService整合Spring示例工程代码demo可以直接导入eclipse。参照网页http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html 完成的webService服务提供。 大致步骤: 1.引入cxf和其他需要的jar包,(本...
JAX-WS + Spring 实现webService示例
本示例演示了如何基于将Apache CXF与Spring Boot结合使用。 快速入门使用Spring Boot来配置一个小的应用程序,其中包括启用了Swagger的CXF JAXRS端点。 重要的 该快速入门可以在2种模式下运行:在您的计算机和...
Webservice入门教程_用CXF编写基于Spring的WebService示例代码
完整可用的spring整合CXF示例项目,包括服务发布端和调用端两个项目,包括CXF拦截器的实现的简单的授权校验
cxf组件 webservice示例代码
CXF+Struts+spring的示例
webservice本地部署很简单,在lib下选取需要的jar包,考到自己的项目中,编写接口和接口的实现类,网上参照的示例很多。
一个简单的WebService CXF 示例
CXF入门教程(2) -- 简单客户端示例文章附带代码,为使用方便,将service和client代码合并到一个工程中。原文地址http://blog.csdn.net/neareast/article/details/7717568
JAVA CXF webservice的示例代码 Eclipse工程
webservice示例(cxf开发的例子),简单的例子。可以学学。