客户端使用List作参数或者返回值时,必须注册,也就是指明序列化器。
axis服务断发布时不需指明。客户端注册List的示例如下:import java.util.List;//...
String uri= "Test";
String serviceName = "Test";
String url = "http://127.0.0.1:8080/axis/services/Test";ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(new QName(uri, serviceName));TypeMappingRegistry registry = service.getTypeMappingRegistry();
TypeMapping map = registry.getDefaultTypeMapping();QName qname = new QName(uri, "ArrayOf_xsd_anyType");
map.register(List.class, 
    qname, 
    new ArraySerializerFactory(), 
    new ArrayDeserializerFactory());Call call = service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName(new QName(uri, "CreatList"));
//call.addParameter("in0", qname, ParameterMode.IN);
call.setReturnType(qname);
List result = (List)call.invoke(new Object[] { in });请自行修改上面代码中serviceName, url, uri, 
其中 ArrayOf_xsd_anyType是你在发布的wsdl中看到的对象类型名。以上代码在axis-1_1中调试通过。

解决方案 »

  1.   

    请问我该在客户端什么地方注册呢?
    我的jbulider自动生成了4个类:
    CsdnSoapBindingStub
    CsdnServiceLocator
    CsdnService
    Csdn该在哪个类的什么地方注册呢?
      

  2.   

    晕, 怎么这么多人喜欢用JBuilder, 那么笨重的东西。
    你不觉得那些生成出来的东西看着眼花?
    俺还是觉得手些的清爽。也许应该在 CsdnSoapBindingStub中吧,那里面不是有些
    _call模样的东西吗?这样搞:
    _call.registerTypeMapping(
                    List.class,
                    qname,
                    new ArraySerializerFactory(),
                    new ArrayDeserializerFactory())
      

  3.   

    我安装您的建议进行了修改
    可是还是出现问题public class CsdnSoapBindingStub extends org.apache.axis.client.Stub implements bene.generated.Csdn {
        private java.util.Vector cachedSerClasses = new java.util.Vector();
        private java.util.Vector cachedSerQNames = new java.util.Vector();
        private java.util.Vector cachedSerFactories = new java.util.Vector();
        private java.util.Vector cachedDeserFactories = new java.util.Vector();    static org.apache.axis.description.OperationDesc [] _operations;    static {
            _operations = new org.apache.axis.description.OperationDesc[2];
            org.apache.axis.description.OperationDesc oper;
            oper = new org.apache.axis.description.OperationDesc();
            oper.setName("main");
            oper.addParameter(new javax.xml.namespace.QName("", "args"), new javax.xml.namespace.QName("http://bene", "ArrayOf_xsd_string"), java.lang.String[].class, org.apache.axis.description.ParameterDesc.IN, false, false);
            oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);
            oper.setStyle(org.apache.axis.enum.Style.RPC);
            oper.setUse(org.apache.axis.enum.Use.ENCODED);
            _operations[0] = oper;        oper = new org.apache.axis.description.OperationDesc();
            oper.setName("CreatList");
            oper.setReturnType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "Array"));
            oper.setReturnClass(java.lang.Object[].class);
            oper.setReturnQName(new javax.xml.namespace.QName("", "CreatListReturn"));
            oper.setStyle(org.apache.axis.enum.Style.RPC);
            oper.setUse(org.apache.axis.enum.Use.ENCODED);
            _operations[1] = oper;      
        }    public CsdnSoapBindingStub() throws org.apache.axis.AxisFault {
             this(null);
        }    public CsdnSoapBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {
             this(service);
             super.cachedEndpoint = endpointURL;
        }    public CsdnSoapBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {
            if (service == null) {
                super.service = new org.apache.axis.client.Service();
            } else {
                super.service = service;
            }
                java.lang.Class cls;
                javax.xml.namespace.QName qName;
                java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;
                java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;
                java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;
                java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;
                java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;
                java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;
                java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;
                java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;
                qName = new javax.xml.namespace.QName("http://bene", "ArrayOf_xsd_string");
                cachedSerQNames.add(qName);
                cls = java.lang.String[].class;
                cachedSerClasses.add(cls);
                cachedSerFactories.add(arraysf);
                cachedDeserFactories.add(arraydf);    }
      

  4.   

    private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {
            try {
                org.apache.axis.client.Call _call =
                        (org.apache.axis.client.Call) super.service.createCall();
                if (super.maintainSessionSet) {
                    _call.setMaintainSession(super.maintainSession);
                }
                if (super.cachedUsername != null) {
                    _call.setUsername(super.cachedUsername);
                }
                if (super.cachedPassword != null) {
                    _call.setPassword(super.cachedPassword);
                }
                if (super.cachedEndpoint != null) {
                    _call.setTargetEndpointAddress(super.cachedEndpoint);
                }
                if (super.cachedTimeout != null) {
                    _call.setTimeout(super.cachedTimeout);
                }
                if (super.cachedPortName != null) {
                    _call.setPortName(super.cachedPortName);
                }
                java.util.Enumeration keys = super.cachedProperties.keys();
                while (keys.hasMoreElements()) {
                    java.lang.String key = (java.lang.String) keys.nextElement();
                    _call.setProperty(key, super.cachedProperties.get(key));
                }
                // All the type mapping information is registered
                // when the first call is made.
                // The type mapping information is actually registered in
                // the TypeMappingRegistry of the service, which
                // is the reason why registration is only needed for the first call.
                synchronized (this) {
                    if (firstCall()) {
                        // must set encoding style before registering serializers
                        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
                        _call.setEncodingStyle(org.apache.axis.Constants.URI_SOAP11_ENC);
                        for (int i = 0; i < cachedSerFactories.size(); ++i) {
                            java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);
                            javax.xml.namespace.QName qName =
                                    (javax.xml.namespace.QName) cachedSerQNames.get(i);
                            java.lang.Class sf = (java.lang.Class)
                                     cachedSerFactories.get(i);
                            java.lang.Class df = (java.lang.Class)
                                     cachedDeserFactories.get(i);
                            _call.registerTypeMapping(cls, qName, sf, df, false);
                        }
                    }
                }
                return _call;
            }
            catch (java.lang.Throwable t) {
                throw new org.apache.axis.AxisFault("Failure trying to get the Call object", t);
            }
        }    public void main(java.lang.String[] args) throws java.rmi.RemoteException {
            if (super.cachedEndpoint == null) {
                throw new org.apache.axis.NoEndPointException();
            }
            org.apache.axis.client.Call _call = createCall();
            _call.setOperation(_operations[0]);
            _call.setUseSOAPAction(true);
            _call.setSOAPActionURI("");
            _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new javax.xml.namespace.QName("http://bene", "main"));        setRequestHeaders(_call);
            setAttachments(_call);
            java.lang.Object _resp = _call.invoke(new java.lang.Object[] {args});        if (_resp instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException)_resp;
            }
            extractAttachments(_call);
        }    public java.lang.Object[] creatList() throws java.rmi.RemoteException {
            if (super.cachedEndpoint == null) {
                throw new org.apache.axis.NoEndPointException();
            }
            org.apache.axis.client.Call _call = createCall();
            _call.setOperation(_operations[1]);
            _call.setUseSOAPAction(true);
            _call.setSOAPActionURI("");
            _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new javax.xml.namespace.QName("http://bene", "CreatList"));        setRequestHeaders(_call);
            setAttachments(_call);
            java.lang.Object _resp = _call.invoke(new java.lang.Object[] {});        if (_resp instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException)_resp;
            }
            else {
                extractAttachments(_call);
                try {
                    return (java.lang.Object[]) _resp;
                } catch (java.lang.Exception _exception) {
                    return (java.lang.Object[]) org.apache.axis.utils.JavaUtils.convert(_resp, java.lang.Object[].class);
                }
            }
        }
      

  5.   

    我应该放在什么地方好呢?
    还有我是不是应该将creatList() 返回值java.lang.Object[]变为ArrayList?
      

  6.   

    你有没收到我的email? 我晚上9点在线, 现场给你诊断!
    QQ 9365863 
    MSN [email protected]