使用Apache CXF创建简单Web Service
2010-05-05 20:09
330 查看
1.创建HelloWorld 接口类
2.创建HelloWorld实现类
3.创建Server端测试类
4.创建Client端测试类
5.测试
首先运行Server类来启动Web Service服务,然后访问http://localhost:9000/HelloWorld?wsdl地址来确定web service启动正确。
运行Client测试类,会在命令行输出Hello kongxx!的message。
package com.googlecode.garbagecan.cxfstudy.helloworld; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService public interface HelloWorld { public @WebResult(name="String")String sayHi(@WebParam(name="text") String text); }
2.创建HelloWorld实现类
package com.googlecode.garbagecan.cxfstudy.helloworld; public class HelloWorldImpl implements HelloWorld { public String sayHi(String name) { String msg = "Hello " + name + "!"; System.out.println("Server: " + msg); 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 { HelloWorld helloWorld = new HelloWorldImpl(); JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); factory.setServiceClass(HelloWorld.class); factory.setAddress("http://localhost:9000/HelloWorld"); factory.setServiceBean(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/HelloWorld"); HelloWorld helloworld = (HelloWorld) factory.create(); System.out.println(helloworld.sayHi("kongxx")); System.exit(0); } }
5.测试
首先运行Server类来启动Web Service服务,然后访问http://localhost:9000/HelloWorld?wsdl地址来确定web service启动正确。
运行Client测试类,会在命令行输出Hello kongxx!的message。
相关文章推荐
- 使用Apache CXF创建简单Web Service
- 使用IDEA创建一个简单的基于Spring Boot的RESTful Web Service
- 使用Apache CXF和Spring集成创建Web Service
- 使用Restlet创建一个简单的web service(Creating a simple web service with Restlet)
- 使用Flash Builder 4和Web Service创建数据为中心的简单应用
- 使用Apache CXF和Spring集成创建Web Service
- 使用Apache CXF和Spring集成创建Web Service
- 使用Apache CXF和Spring集成创建Web Service(zz)
- 使用Apache CXF创建Web Service
- 使用Apache CXF和Spring集成创建Web Service
- IntelliJ初使用:IntelliJ创建简单的maven项目
- iOS——NSTimer的使用,计时器的简单创建
- 使用php socket创建简单服务器
- 使用angularjs创建简单表格
- 使用 Swift 创建简单的二维码扫描应用
- Nunit简单创建使用
- 使用Nana 0.8创建一个简单的记事本
- 使用Cocos studio创建一个简单的工程
- [C++]数据结构:公式化描述的堆栈Stack的简单创建与使用
- CoreText 使用教程:以创建一个简单的杂志应用为例