没有为数组类型定义反序列化器

时间:2015-12-21 14:07:51

标签: java web-services soap consumer

我正在尝试使用webservice并遇到问题。我导入了WSDL文件并生成了Java类。我可以连接到webservice,但是当我要求数据时,我会收到这样的错误。

WSDL文件:https://www.geckobooking.dk/api7/webservice.php?WSDL

客户代码

    GeckobookingServiceLocator service = new GeckobookingServiceLocator();
    service.setMaintainSession(true);
    GeckobookingPortType port = service.getgeckobookingPort();
    boolean connect = port.connect(new BigInteger("xxxx"), "name", "secretKey");
    System.out.println("Connect status:" + connect); // that works fine, return true.
    // issue happens in that line
    CustomerHandles customer_GetAll = port.customer_GetAll();

customer_GetAll

问题发生在这一行:

  

java.lang.Object _resp = _call.invoke(new java.lang.Object [] {});

这是一个完整的方法

   public geckobooking_pkg.CustomerHandles customer_GetAll() throws java.rmi.RemoteException {
        if (super.cachedEndpoint == null) {
            throw new org.apache.axis.NoEndPointException();
        }
        org.apache.axis.client.Call _call = createCall();
        _call.setOperation(_operations[14]);
        _call.setUseSOAPAction(true);
        _call.setSOAPActionURI("urn:geckobookingAction");
        _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
        _call.setOperationName(new javax.xml.namespace.QName("urn:geckobooking", "Customer_GetAll"));

        setRequestHeaders(_call);
        setAttachments(_call);
        try { 
            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 (geckobooking_pkg.CustomerHandles) _resp;
                } catch (java.lang.Exception _exception) {
                    return (geckobooking_pkg.CustomerHandles) org.apache.axis.utils.JavaUtils.convert(_resp, geckobooking_pkg.CustomerHandles.class);
                }
            }
        } catch (org.apache.axis.AxisFault axisFaultException) {
            throw axisFaultException;
        }
    }

错误(使用自动生成的类时)

org.xml.sax.SAXException: No deserializer defined for array type {http://schemas.xmlsoap.org/soap/encoding/}Struct
    at org.apache.axis.encoding.ser.ArrayDeserializer.onStartElement(ArrayDeserializer.java:276)
    at org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:393)
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1048)
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)
    at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:345)
    at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)
    at org.apache.axis.client.Call.invoke(Call.java:2467)
    at org.apache.axis.client.Call.invoke(Call.java:2366)
    at org.apache.axis.client.Call.invoke(Call.java:1812)
    at geckobooking_pkg.GeckobookingBindingStub.customer_GetAll(GeckobookingBindingStub.java:1420)
    at geckobooking.SOAPClientSAAJ.auto(SOAPClientSAAJ.java:24)
    at geckobooking.SOAPClientSAAJ.main(SOAPClientSAAJ.java:11)

我知道这是什么问题,但我不知道如何解决它。

如果我使用SOAPMessage方法(当我自己构建消息时),我会得到一个响应

真实回复

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:geckobooking" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
    <ns1:Customer_GetAllResponse>
      <Customer_GetAllReturn xsi:type="ns1:CustomerHandles">
        <CustomerHandles SOAP-ENC:arrayType="SOAP-ENC:Struct[5003]" xsi:type="SOAP-ENC:Array">
          <item xsi:type="SOAP-ENC:Struct"><Id xsi:type="xsd:string">121</Id></item>
          <item xsi:type="SOAP-ENC:Struct"><Id xsi:type="xsd:string">122</Id></item>
          <item xsi:type="SOAP-ENC:Struct"><Id xsi:type="xsd:string">123</Id></item>
          <item xsi:type="SOAP-ENC:Struct"><Id xsi:type="xsd:string">124</Id></item>
          <item xsi:type="SOAP-ENC:Struct"><Id xsi:type="xsd:string">125</Id></item>
        </CustomerHandles>
      </Customer_GetAllReturn>
    </ns1:Customer_GetAllResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

CustomerHandles类的定义

/**
 * CustomerHandles.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
 */

package geckobooking_pkg;

public class CustomerHandles  implements java.io.Serializable {

private java.lang.Object customerHandles;

public CustomerHandles() {
}

public CustomerHandles(
       java.lang.Object customerHandles) {
       this.customerHandles = customerHandles;
}


/**
 * Gets the customerHandles value for this CustomerHandles.
 * 
 * @return customerHandles
 */
public java.lang.Object getCustomerHandles() {
    return customerHandles;
}


/**
 * Sets the customerHandles value for this CustomerHandles.
 * 
 * @param customerHandles
 */
public void setCustomerHandles(java.lang.Object customerHandles) {
    this.customerHandles = customerHandles;
}

private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
    if (!(obj instanceof CustomerHandles)) return false;
    CustomerHandles other = (CustomerHandles) obj;
    if (obj == null) return false;
    if (this == obj) return true;
    if (__equalsCalc != null) {
        return (__equalsCalc == obj);
    }
    __equalsCalc = obj;
    boolean _equals;
    _equals = true && 
        ((this.customerHandles==null && other.getCustomerHandles()==null) || 
         (this.customerHandles!=null &&
          this.customerHandles.equals(other.getCustomerHandles())));
    __equalsCalc = null;
    return _equals;
}

private boolean __hashCodeCalc = false;
public synchronized int hashCode() {
    if (__hashCodeCalc) {
        return 0;
    }
    __hashCodeCalc = true;
    int _hashCode = 1;
    if (getCustomerHandles() != null) {
        _hashCode += getCustomerHandles().hashCode();
    }
    __hashCodeCalc = false;
    return _hashCode;
}

// Type metadata
private static org.apache.axis.description.TypeDesc typeDesc =
    new org.apache.axis.description.TypeDesc(CustomerHandles.class, true);

static {
    typeDesc.setXmlType(new javax.xml.namespace.QName("urn:geckobooking", "CustomerHandles"));
    org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
    elemField.setFieldName("customerHandles");
    elemField.setXmlName(new javax.xml.namespace.QName("", "CustomerHandles"));
    elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "anyType"));
    elemField.setNillable(false);
    typeDesc.addFieldDesc(elemField);
}

/**
 * Return type metadata object
 */
public static org.apache.axis.description.TypeDesc getTypeDesc() {
    return typeDesc;
}

/**
 * Get Custom Serializer
 */
public static org.apache.axis.encoding.Serializer getSerializer(
       java.lang.String mechType, 
       java.lang.Class _javaType,  
       javax.xml.namespace.QName _xmlType) {
    return 
      new  org.apache.axis.encoding.ser.BeanSerializer(
        _javaType, _xmlType, typeDesc);
}

/**
 * Get Custom Deserializer
 */
public static org.apache.axis.encoding.Deserializer getDeserializer(
       java.lang.String mechType, 
       java.lang.Class _javaType,  
       javax.xml.namespace.QName _xmlType) {
    return 
      new  org.apache.axis.encoding.ser.BeanDeserializer(
        _javaType, _xmlType, typeDesc);
}

}

我非常感谢对这个问题的任何帮助。

1 个答案:

答案 0 :(得分:1)

CustomerHandles生成的类代码中,您能否尝试用"urn:geckobooking中的空字符串""替换typeDesc.setXmlType(new javax.xml.namespace.QName("urn:geckobooking", "CustomerHandles"));

即。尝试使用typeDesc.setXmlType(new javax.xml.namespace.QName("", "CustomerHandles"));

运行webservice调用

显然,上述建议对你没有用 - 这是基于我几年的回忆,类似的东西对我有用。

我想,有必要为您尝试通过网络发送和接收的自定义数组对象定义自己的序列化程序反序列化程序在Axis WSDD文件中)。 Difference between wsdd and wsdl

请参阅What_Axis_can_not_send_via_SOAP中关于使用<typeMapping />为自定义数组类型定义自己的序列化程序和反序列化程序的“当Bean不够 - 自定义序列化”部分。如果你不是开发上述Web服务的人,我认为你需要告知Web服务团队这个问题,因为堆栈跟踪说默认 - ArrayDeserializer对于你的数组对象是不够的。