webservice开发---------如何使用cxf发布soap方式的web服务
2018-09-12 17:08
1276 查看
使用CXF框架发布web服务,简单易用,下面结合实际案例讲解
一:配置web.xml,CXFServlet 负责截获/pubinterface/services/*的请求
[code]<servlet> <description>Apache CXF Endpoint</description> <display-name>cxf</display-name> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/pubinterface/services/*</url-pattern> </servlet-mapping>
二:配置cxf对应的beans.xml文件,address为 /OrderInterfaceService
[code]<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <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" /> <!--发布的接口--> <jaxws:endpoint id="OrderInterfaceService" implementor="#orderInterfaceServiceImpl" address="/OrderInterfaceService"> <jaxws:features> <bean class="org.apache.cxf.feature.LoggingFeature" /> </jaxws:features> </jaxws:endpoint> </beans>
其中jaxws 是配置 SOAP 方式的 Web 服务,有 jaxws:server、jaxws:endpoint、 jaxws:client 三个元素,jaxws:server 和 jaxws:endpoint 是等效的,都用于发布 Web 服务,出 现 jaxws:endpoint 的原因是 JAX-WS 规范中使用 EndPoint 发布 Web 服务,CXF 为了和 JAX-WS 对应,提供了这个与 jaxws:server 功能一样的配置元素;与jaxws可以一样配置的有jaxrs,jaxrs 是 REST 方式的 Web 服务,有 jaxrs:server、jaxrs:client 两个元素。
三:接口定义方法
[code]@WebService public interface OrderInterfaceService { /** * @param inputInfo * @return */ @WebMethod(operationName = "applyOrder") @WebResult(name = "outputInfo") String applyOrder(@WebParam(name="inputInfo") String inputInfo); /** * @param inputInfo * @return */ @WebMethod(operationName = "orderProcessDetail") @WebResult(name = "outputInfo") String orderProcessDetail(@WebParam(name="inputInfo") String inputInfo); }
四:实现类
[code]@Service public class OrderInterfaceServiceImpl implements OrderInterfaceService { //实现类中的方法体无具体意义 @Override public String applyOrder(String inputInfo) { return "Interface method : applyOrder, param : " +inputInfo; } @Override public String orderProcessDetail(String inputInfo) { //TODO return "Interface method : orderProcessDetail, param : " +inputInfo; } }
启动服务,访问发布地址,如案例中项目名称为soc,则wsdl地址为:http://localhost:8080/soc/pubinterface/services/OrderInterfaceService?wsdl,如果为wsdl文档即正确发布
阅读更多相关文章推荐
- webservice接口常见问题1:客户端使用SOAP方式调用CXF服务时异常
- WebService- 使用 CXF 开发 SOAP 服务
- Webservice的cxf开发_使用spring发布服务+ajax调用服务
- Spring 集成CXF框架发布Webservice服务 和 使用jdk生成Webservice clinet
- Maven搭建webService (二) 创建服务端---使用web方式发布服务
- 使用CXF(JaxWsServerFactoryBean、ServerFactoryBean)编码的方式发布WebService服务
- java开发中使用CXF发布rest风格的webservice服务
- 使用SOAP开发java web服务--Axis开发方案
- 使用SOAP开发java web服务--Axis开发方案
- 使用Cxf发布Webservice服务,如果待发布的接口中有重载方法,怎么处理??[转]
- Webservice学习笔记二,使用Axis发布简单的Web服务
- CXF Spring开发WebService,基于SOAP和REST方式
- 使用SOAP开发java web服务--Axis开发方案
- 使用SOAP开发java web服务--Axis开发方案
- 使用SOAP开发java web服务--Axis开发方案(转)
- 使用SOAP开发java web服务--Axis开发方案
- 用JAX-WS开发WebService服务端并用tomcat发布Web服务
- Web应用中使用CXF不基于Spring的WebService发布
- WebService从零到项目开发使用3—技术研究之Axis2 POJO开发Web服务
- WebService开发(二) 如何使用Soap扩展 http://www.cnblogs.com/wayne-ivan/archive/2007/06/19/788541.html