cxf根据wsdl生成webserivice服务端

1.根据wsdl文件生成相关代码

wsdl2java用法: 

wsdl2java -p com -d src -all  aa.wsdl 

-p  生成代码的包名: 

-d  指定要产生代码所在目录 

-client 生成web service客户端代码 

-server 生成web  service服务器代码 

-impl 生成web service的实现代码 

-ant  生成build.xml文件 

-all 生成所有代码:types,service proxy,,service interface, server mainline, client mainline,


2、maven依赖:

<properties>

    <cxf.version>2.7.12</cxf.version>
</properties>

<dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
    </dependency>

3、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>qy-game-base</display-name>


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/applicationContext.xml
</param-value>
</context-param>
 
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

    <listener>
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
    </listener>
 
<servlet>
   <servlet-name>CXFService</servlet-name>
   <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
 
<servlet-mapping>
   <servlet-name>CXFService</servlet-name>
   <url-pattern>/cxf/*</url-pattern>
</servlet-mapping>


</web-app>



4、applicationContext.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" 
        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"> 
          
   <import resource="classpath:META-INF/cxf/cxf.xml" />
   <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
   <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />


   <jaxws:endpoint  id = "dataSyncService"  address = "/dataSyncService" 
         implementorClass = "com.qy.crack.mm.action.DataSync" > 
         <jaxws:implementor > 
             <bean  id = "dataSyncController" 
                 class = "com.qy.crack.mm.action.DataSyncController" > 
             </bean > 
         </jaxws:implementor > 
  </jaxws:endpoint > 
    
</beans>  


遇到错误:

org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"http://schema.ib.sdp.huawei.com", local:"ID")。所需元素为<{}ID>,<{}type> 

原因:因为在客户端传过来的xml中对属性

<ns2:userID>
   <ns3:ID xmlns:ns3="http://schasdlsds.asdsad.com">1527931163</ns3:ID>
<ns4:type xmlns:ns4="http://schasdlsds.asdsad.com">1</ns4:type>

 </ns2:userID>

添加了命名空间,而我生成的代码中,命名空间是空的,所以报错,只要将@XmlElement(name = "ID", namespace = "", required = true)填入namespace=“http://schasdlsds.asdsad.com”即可

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserID", namespace = "http://www.csapi.org/schema/parlayx/data/v1_0", propOrder = {
    "id",
    "type"
})
public class UserID {


    @XmlElement(name = "ID", namespace = "", required = true)
    protected String id;
    @XmlElement(namespace = "")
    protected int type;


    /**
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getID() {
        return id;
    }


    /**
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setID(String value) {
        this.id = value;
    }


    /**
     * 
     */
    public int getType() {
        return type;
    }


    /**
     * 
     */
    public void setType(int value) {
        this.type = value;
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风中情

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值