cxf soap返回_通过CXF,开发soap协议接口

本文介绍了如何通过Apache CXF来开发SOAP协议接口。首先,添加CXF的依赖到pom.xml文件,接着配置web.xml和cxf.xml文件。然后,定义接口并使用CXF服务注解,最后实现接口并部署到Tomcat服务器进行测试。
摘要由CSDN通过智能技术生成

1. 引入cxf的jar包

pom文件里面直接增加依赖

< dependency>

junit groupId>

junit artifactId>

4.11

test

org.springframework

spring- webmvc artifactId>

4.0.0.RELEASE

org.apache.cxf

apache-cxf

2.4.3

pom type>

2. 配置web.xml文件

xml version= "1.0" encoding= "UTF-8" ?>

< web-app xmlns= "http://xmlns.jcp.org/xml/ns/javaee"

xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation= "http://xmlns.jcp.org/xml/ns/javaee

http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version= "3.1" >

< display-name >Archetype Created Web Application

< context-param >

contextConfigLocation

classpath:config/spring/metadataWebService-spring.xml

org.springframework.web.context.ContextLoaderListener

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

CXFServlet

/services/*

encodingFilter

< filter-class> org.springframework.web.filter.CharacterEncodingFilter

encoding

UTF-8

forceEncoding

true

encodingFilter

/*

web-app>

3. 配置cxf.xml文件

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"

xmlns:context= "http://www.springframework.org/schema/context"

xmlns:jaxrs= "http://cxf.apache.org/jaxrs"

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

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context.xsd

http://cxf.apache.org/jaxrs

http://cxf.apache.org/schemas/jaxrs.xsd" >

scope= "prototype" >

class= "org.apache.cxf.jaxws.spring.JaxWsWebServicePublisherBeanPostProcessor" >

< jaxws:server id= "ResumeUpload" serviceClass= "com.sigmatrix.soap.webService.DemoService"

address= "/ResumeUpload" >

beans>

4. 要开放的接口加上cxf服务的注解

接口类:

@WebService (portName = "inbound.webServices.ticket.saServiceSoap12" )

@javax.xml.ws.soap. MTOM

public interface DemoService {

@WebMethod

public String demo( @WebParam(name = "demo") Demo demo);

}

接口实现类:

@Component

@WebService (portName = "inbound.webServices.ticket.saServiceSoap12" )

@BindingType (value = "http://www.w3.org/2003/05/soap/bindings/HTTP/" )

public class DemoServiceImpl implements DemoService {

public String Demo(Demo demo) {

String userName = demo.getUserName();

String password= demo.getPassword();

return "success";

}

Demo实体类:

public Class Demo() {

public String userName;

public String password;

public String getUserName() {

return userName;

}

public void setUserName(String userName) {

this.userName = userName;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password= password;

}

}

5. 部署到tomcat启动即可,测试访问 ip:端口号//项目名称/services/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值