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"?> 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(); } }
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |