使用CXF发布webService
来源:互联网 发布:菜鸟阎王网络剧百度云 编辑:程序博客网 时间:2024/05/16 11:27
1、下载CXF,并配置环境变量
将bin目录配置到path中
2、新建java project,导入cxf的jar包,最终项目结构如下:
3、建立接口及实现类
1)接口
package com.tgb.web.webservice;
import javax.jws.WebService;@WebServicepublic interface HelloWorld {public String sayHi(String str);}
2)实现类:
package com.tgb.web.webservice.impl;
import java.util.Date;import javax.jws.WebService;import com.tgb.web.webservice.HelloWorld;@WebService(endpointInterface="com.tgb.web.webservice.HelloWorld",serviceName="HelloWorld")public class HelloWorldBean implements HelloWorld {@Overridepublic String sayHi(String str) {return "hello,"+str+",现在时间是:"+new Date();}}
4、利用Endpoint发布webService,即客户端如下:
package lee;
import javax.xml.ws.Endpoint;import com.tgb.web.webservice.HelloWorld;import com.tgb.web.webservice.impl.HelloWorldBean;public class ServerMain {public static void main(String[] args) {HelloWorld hw=new HelloWorldBean();//调用Endpoint的publish方法发布Web ServiceEndpoint.publish("http://192.168.1.108:8088/HelloWorld", hw);System.out.println("webService 发布成功!");}}
5、在浏览器中访问地址:http://192.168.1.108:8088/HelloWorld?wsdl ,就可以看到发布的wsdl页面了。
=================================================================
客户端:
1、新建立java项目WS_Client,运行cmd,将目录定位到WS_Client项目下的src目录下,然后输入wsdl2java http://192.168.1.108:8088/HelloWorld?wsdl,就可以在客户端生成调用wsdl的代理对象来,如下图:
2、建立测试类ClientMain :
package lee;import com.tgb.web.webservice.impl.HelloWorld;public class ClientMain {public static void main(String[] args) {HelloWorld factory=new HelloWorld();com.tgb.web.webservice.HelloWorld hWorld= factory.getHelloWorldWsPort();System.out.println(hWorld.sayHi("张三"));}}
3、运行测试类,就可以成功调用。最后输出结果如下:
hello,张三,现在时间是:Wed Mar 23 22:25:24 CST 2016
1 0
- 使用CXF发布webService
- 使用CXF发布WebService
- 使用CXF框架发布webservice
- 使用cxf发布webservice总结
- WebService学习笔记-使用CXF发布Webservice
- 使用cxf发布webservice(JavaApplication)
- 使用cxf发布WebService(Spring)
- CXF发布WebService使用SoapUI测试
- cxf发布webservice,使用maven工程
- 使用CXF发布WebService服务简单实例
- cxf发布webservice 简单使用步骤备忘
- 使用Spring + CXF 发布WebService服务
- cxf-dosgi 发布webservice
- cxf+spring发布webservice
- cxf发布webservice
- cxf+spring发布webservice
- CXF发布webservice入门
- Mule发布webservice--cxf
- Android 开源框架介绍序列表
- c++解最大公约数(辗转相除法)
- 通过例子学习 Keystone - 每天5分钟玩转 OpenStack(19)
- 俄罗斯方块类的实现以及方块在画布中显示
- Markdown 简明语法手册
- 使用CXF发布webService
- 《北京现代流行语》读后感
- 拷贝文件
- Apktool的使用
- Eclipse配置Struts2问题:ClassNotFoundException: org...dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- x86上的那些UNIX——System V篇(Solaris、SCO)
- 第五届华中区程序设计邀请赛暨武汉大学第十四届校赛 网络预选赛
- 【设计模式】——五问单例模式
- WOJ 1608 Calculation(状态压缩)