cxf 实战1
来源:互联网 发布:讲文明 懂礼仪 知荣辱 编辑:程序博客网 时间:2024/05/20 23:34
下面来看看HelloWorld的具体例子。
1.创建HelloWorld 接口类
- package com.googlecode.garbagecan.cxfstudy.helloworld;
- import javax.jws.WebMethod;
- import javax.jws.WebParam;
- import javax.jws.WebResult;
- import javax.jws.WebService;
- @WebService
- public interface HelloWorld {
- @WebMethod
- @WebResult String sayHi(@WebParam String text);
- }
2.创建HelloWorld实现类
- package com.googlecode.garbagecan.cxfstudy.helloworld;
- public class HelloWorldImpl implements HelloWorld {
- public String sayHi(String name) {
- String msg = "Hello " + name + "!";
- return msg;
- }
- }
3.创建Server端测试类
- package com.googlecode.garbagecan.cxfstudy.helloworld;
- import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
- // http://localhost:9000/HelloWorld?wsdl
- public class Server {
- public static void main(String[] args) throws Exception {
- JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
- factory.setServiceClass(HelloWorldImpl.class);
- factory.setAddress("http://localhost:9000/ws/HelloWorld");
- factory.create();
- System.out.println("Server start...");
- Thread.sleep(60 * 1000);
- System.out.println("Server exit...");
- System.exit(0);
- }
- }
4.创建Client端测试类
- package com.googlecode.garbagecan.cxfstudy.helloworld;
- import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
- public class Client {
- public static void main(String[] args) {
- JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
- factory.setServiceClass(HelloWorld.class);
- factory.setAddress("http://localhost:9000/ws/HelloWorld");
- HelloWorld helloworld = (HelloWorld) factory.create();
- System.out.println(helloworld.sayHi("kongxx"));
- System.exit(0);
- }
- }
5.测试
首先运行Server类来启动Web Service服务,然后访问http://localhost:9000/ws/HelloWorld?wsdl地址来确定web service启动正确。
运行Client测试类,会在命令行输出Hello kongxx!的message。
- cxf 实战1
- CXF实战
- CXF实战
- Apache CXF实战
- Apache CXF实战转载
- Cxf WebService实战
- cxf+spring webservice实战
- CXF实战(一)
- cxf实战一
- IDEA8实战-CXF版HelloWorld
- 实战Web Service with CXF
- 实战CXF调用Webxml天气预报服务
- 实战CXF调用Webxml天气预报服务
- Eclipse+CXF框架开发Web服务实战
- Eclipse+CXF框架开发Web服务实战
- 实战CXF调用Webxml天气预报服务
- CXF实战之集成Spring(三)
- CXF实战之拦截器Interceptor(四)
- 研究生导师的肺腑之言(摘录)
- GNU内嵌汇编 ARM版 (ZZ)
- md5算法描述
- 关键字
- ACM经典问题--布线问题(三)
- cxf 实战1
- 关于java中的Collection Framework
- Apache CXF实战之二:集成Sping与Web容器
- Vmware What is the location of the directory of C header files that match your running问题的解决
- Apache CXF实战之三:传输Java对象
- vim配置
- 写给在工厂上班的一封信
- 20131019152244秒ABC 博文测试篇驻马店
- Apache CXF实战之四:构建RESTful Web Service