cxf发布webservice及客户端调用

今天抽时间整理了下cxf发布webservice的具体步骤,写下来供大家参考,废话不多说,直接上贴图,上代码:

注:该此文档所有项目源码及jar包下载地址为:cxf发布webservice及客户端调用示例demo下载

将下载的demo(包括serviceserverdemo及serviceclientdemo,bat文件在serviceclientdemo的src下)导入eclipse即可运行使用,编译时可能需要修改jdk版本,如果导入有错,可新建web项目,按所下载demo的结构搭建即可!下面为各demo的大体结构介绍

一,服务端

整体项目结构如下



1,xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>


<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>


<listener>
<listener-class>
  org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

2,导入与CXF框架有关的xml及发布WebService接口

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<!--导入与CXF框架有关的xml-->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />


<!--发布WebService接口-->
<jaxws:endpoint id="service"
implementor="com.test.cxf.service.impl.ServiceImpl" address="/IService">
</jaxws:endpoint>
</beans>

二,客户端

整体项目结构


1,bat文件内容




2,调用示例代码:
public static void main(String[] args) {
try {
ServiceImplServiceLocator iService = new ServiceImplServiceLocator();
ServiceImplServiceSoapBindingStub service = (ServiceImplServiceSoapBindingStub) iService.getServiceImplPort();
String  str = service.get("test");
System.out.println(str+"  ---------------------");
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值