加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

cxf发布webservice及客户端调用

发布时间:2020-12-16 22:25:17 所属栏目:安全 来源:网络整理
导读:今天抽时间整理了下cxf发布webservice的具体步骤,写下来供大家参考,废话不多说,直接上贴图,上代码: 注:该此文档所有项目源码及jar包下载地址为:cxf发布webservice及客户端调用示例demo下载 将下载的demo(包括serviceserverdemo及 serviceclientdemo

今天抽时间整理了下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(); } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读