Xfire处理复杂类型的方法

来源:互联网 发布:淘宝店铺首页代码 编辑:程序博客网 时间:2024/05/17 04:13

最近尝试使用xfire生成ws,然后使用java进行调用,可是xfire只能支持一般类型的返回,对于复杂类型的数据返回需要进行配置,在网上找到比较好的一片文章,如下,拿来学习,但是按照这位仁兄写的我做了测试,虽然在启动tomcat中没有报错,但是在http://localhost:8181/xfireDemo/services/HelloService?wsdl (这是个测试链接)时发生错误,提示Couldn't create type for property list on interface com.ywb.xfire.HelloService: Cannot create mapping for java.util.List, unspecified component type for interface java.util.List说明xfire还是不认识List这个复杂类型。我还会跟进寻求解决,这篇文章也帖出来,个人认为还是有参考价值的。

 

     在WebServices的开发中,通常要处理处长复杂的类型,如返回的是Collection类,或参数是Collection类,或返回的是自定义对象类型,或者参数是自定义对象类型的类,都需要编写className.aegis.xml文件,这种处理方式与axis差不多一样,只不过axis是在service.wsdd中配置。
如有以下接口

package com.efs.xfire.pojo;

import java.util.*;

public interface CollectionsDemo {
    
public int getCollectionsRowCount(List list);
    
public List getUserList();
}


在该接口的同一包下,需进行如下配置

<?xml version="1.0" encoding="UTF-8"?>
<mappings>
    
<mapping>
        
<method name="getCollectionsRowCount">
            
<parameter index="0" componentType="java.lang.String"/>
        
</method>
        
<!-- 返回的类型是Map的话,做法和List一样。但定义的类型,是Map中的Value部分 -->
        
<method name="getUserList"> 
            
<return-type componentType="com.efs.xfire.entity.User"/>
        
</method>
    
</mapping>
</mappings>

只要是类中的方法返回类型或参数是对象类型(除java基本类型外或类集)都需要做相关的配置。

要作为WS发布的类务类,都需要在services.xml文件中作相应的配置

<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
    
<name>HelloWorldService</name>
    
<namespace>http://efs.com/HelloWorldService</namespace>
    
<serviceClass>
        com.efs.xfire.pojo.HelloWorldService
    
</serviceClass>
    
<implementationClass>
        com.efs.xfire.pojo.HelloWorldServiceImpl
    
</implementationClass>
</service>

</beans>
原创粉丝点击