我在实现服务器端用Java提供Web services,客户端程序.Net调用,因为参数及返回值复杂,都是自定义类型,虽然可以通过xml字符串方式,但是感觉不好用,具体孰优孰劣没有进一步分析。
找了一下,网上大都讲的是AXIS中配置service.wsdd,无奈我用的是XFire。最后终于找到,转自:
在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();
}
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 >
< 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 >
< 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 >