axis处理自定义对象

axis处理自定义对象

最近的一个项目又要用到webservice(axis),上次为了赶时间完成任务,简单的找了些例子然后就这样用了,还好项目里本来就有对象和xml之间转换的接口,所以要传的对象一律转换成xml,然后传字符串。
        尝试了N久才搞定了传输属性不是基本数据类型的问题。简单帖个代码:

1.server-config.wsdd

  < service name = " sendUser "  provider = " java:RPC " >
       
<!--  发布特定的方法,多个方法用逗号隔开  -->
      
< parameter name = " allowedMethods "  value = " getUserByUserId " />
      
< parameter name = " className "  value = " cn.gov.zjport.suzhou.webservice.GetUser4WebServiceImpl " />
      
< beanMapping languageSpecificType = " java:cn.gov.zjport.suzhou.domain.CustomUser "   qname = " ns:CustomUser "  xmlns:ns = " urn:GetUser4WebService " />
      
< beanMapping languageSpecificType = " java:cn.gov.zjport.suzhou.domain.CustomRole "   qname = " ns:CustomRole "  xmlns:ns = " urn:GetUser4WebService " />
      
< beanMapping languageSpecificType = " java:cn.gov.zjport.suzhou.domain.CustomUserRole "   qname = " ns:CustomUserRole "  xmlns:ns = " urn:GetUser4WebService " />
 
</ service >
2.客户端测试代码
QName qn  =   new  QName( " urn:GetUser4WebService " , " CustomUser " );
             QName qn1 
=   new  QName( " urn:GetUser4WebService " , " CustomRole " );
             QName qn2 
=   new  QName( " urn:GetUser4WebService " , " CustomUserRole " );
             call.setTargetEndpointAddress(
new  URL( " http://localhost:8080/suzhouPlatform/webServices/sendUser " ) ); 
             call.setOperationName(
new  QName( " http://localhost:8080/suzhouPlatform/webServices/sendUser " , " getUserByUserId " ));
             call.registerTypeMapping(CustomUser.
class , qn, new  BeanSerializerFactory(CustomUser. class , qn), new  BeanDeserializerFactory(CustomUser. class , qn));
             call.registerTypeMapping(CustomRole.
class , qn1, new  BeanSerializerFactory(CustomRole. class , qn1), new  BeanDeserializerFactory(CustomRole. class , qn1));
             call.registerTypeMapping(CustomUserRole.
class , qn2, new  BeanSerializerFactory(CustomUserRole. class , qn2), new  BeanDeserializerFactory(CustomUserRole. class , qn2));
             Object result 
=  call.invoke( new  String[] {"admin"} );
大概代码就这样了^_^

你可能感兴趣的:(axis处理自定义对象)