jeffy

BlogJava 首页 新随笔 联系 聚合 管理
  70 Posts :: 1 Stories :: 14 Comments :: 0 Trackbacks
  服务器端定义:

public class TestService {
 
 public String getStr(String input) {
  return "Input string:"+input;
 }
 
 public Bean getBean(Bean bean) {
  System.out.println("Bean Name:"+bean.getName());
  bean.setName(bean.getName()+"OK");
  
  Bean bb = new Bean();
  bb.setName("haha");
  return bb;
 }
 
 public Bean[] getBeans(String str) {
  Bean[] rets = new  Bean[2];
  Bean bean1 = new Bean();
  bean1.setName("name 1");
  Bean bean2 = new Bean();
  bean2.setName("name 2");
  
  rets[0] = bean1;
  rets[1] = bean2;
  return rets;
 }

}





server-config.wsdd中的配置:

自定义类
<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle="" qname="ns6:Bean" serializer="org.apache.axis.encoding.ser.BeanSerializerFactory" type="java:com.test.bean.Bean" xmlns:ns6="http://bean.test.com"/>

数组
<typeMapping xmlns:ns7="http://bean.test.com" qname="ns7:ArrayOf_Bean" type="java:com.test.bean.Bean[]" serializer="org.apache.axis.encoding.ser.ArraySerializerFactory" deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory" encodingStyle="" /> 

客户端调用:
          String endpoint = "http://localhost:8081/axistest/services/TestService";

            Service service3 = new Service();
            Call call3 = (Call) service3.createCall();
            QName qn3 = new QName("http://bean.test.com","ArrayOf_Bean");
            //注册 bean
            call3.registerTypeMapping(Bean.class,qn,new BeanSerializerFactory(Bean.class, qn),new BeanDeserializerFactory(Bean.class, qn));
            call3.registerTypeMapping(Bean[].class,qn3,new BeanSerializerFactory(Bean[].class, qn3),new BeanDeserializerFactory(Bean[].class, qn3));
            call3.setTargetEndpointAddress(new java.net.URL(endpoint));
            call3.setOperationName(new QName("getBeans"));
            call3.addParameter("arg1", qn, ParameterMode.IN);
   call3.setReturnType(qn,Bean.class);

   java.util.ArrayList ret3 = (java.util.ArrayList) call3.invoke(new Object[] {"test--"});
            System.out.println((ret3==null)?"null":(""+ret3.size())); 


 
posted on 2008-04-01 16:07 Live-in Java 阅读(538) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: