微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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(); } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐