You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by "Gupta, Ankit" <an...@informatica.com> on 2003/10/01 16:22:05 UTC

RE: Axis using wrong encoding for array in Doc/literal

Thank You Anne for your reply.
After this I tried out defining the array in the wsdl in the same way as 
axis is sending the response on wire and the web service worked with .NET
But now axis generates wrong client stubs from the wsdl


My java Class is
-------------------------------------------------------------
service1.java
--------------------------------------------------------------
public class service1 {
	public bean1 returnarr() {
		bean1 a=new bean1();
		int[] b=new int[3];
		b[0]=1;
		b[1]=2;
		b[2]=3;
		a.setMyArr(b);
		a.setA(6);
		return a;
	}
	public int[] echo() {
		int[] a=new int[2];
		a[0]=1;
		a[1]=2;
		return a;
	}
}



My Wsdl that I send to .net is

In this wsdl I have fixed the echo method to have exactly the same signature as axis
sends arrays back on wire
-----------------------------------------------------------
Wsdl
-----------------------------------------------------------
  <?xml version="1.0" encoding="UTF-8" ?> 
- <wsdl:definitions targetNamespace="http://DefaultNamespace" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://DefaultNamespace" xmlns:intf="http://DefaultNamespace" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <wsdl:types>
- <schema elementFormDefault="qualified" targetNamespace="http://DefaultNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
- <complexType name="ArrayOf_xsd_int">
- <complexContent>
- <restriction base="soapenc:Array">
  <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]" /> 
  </restriction>
  </complexContent>
  </complexType>
- <complexType name="bean1">
- <sequence>
  <element name="a" type="xsd:int" /> 
  <element name="myArr" nillable="true" type="xsd:int" minOccurs="0" maxOccurs="unbounded" /> 
  </sequence>
  </complexType>
- <element name="returnarr">
  <complexType /> 
  </element>
- <element name="returnarrResponse">
- <complexType>
- <sequence>
  <element name="returnarrReturn" type="impl:bean1" /> 
  </sequence>
  </complexType>
  </element>
- <element name="echo">
  <complexType /> 
  </element>
- <element name="echoResponse">
- <complexType>
- <sequence>
  <element name="echoReturn" type="soapenc:echoReturn" /> 
  </sequence>
  </complexType>
  </element>
- <complexType name="echoReturn">
- <sequence>
  <element name="item" type="xsd:int" minOccurs="0" maxOccurs="unbounded" /> 
  </sequence>
  </complexType>
  </schema>
- <schema elementFormDefault="qualified" targetNamespace="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://www.w3.org/2001/XMLSchema">
- <complexType name="echoReturn">
- <sequence>
  <element name="item" type="xsd:int" minOccurs="0" maxOccurs="unbounded" /> 
  </sequence>
  </complexType>
  <element name="item" type="xsd:int" /> 
  </schema>
  </wsdl:types>
- <wsdl:message name="returnarrResponse">
  <wsdl:part element="intf:returnarrResponse" name="parameters" /> 
  </wsdl:message>
- <wsdl:message name="echoResponse">
  <wsdl:part element="intf:echoResponse" name="parameters" /> 
  </wsdl:message>
- <wsdl:message name="returnarrRequest">
  <wsdl:part element="intf:returnarr" name="parameters" /> 
  </wsdl:message>
- <wsdl:message name="echoRequest">
  <wsdl:part element="intf:echo" name="parameters" /> 
  </wsdl:message>
- <wsdl:portType name="service1">
- <wsdl:operation name="returnarr">
  <wsdl:input message="intf:returnarrRequest" name="returnarrRequest" /> 
  <wsdl:output message="intf:returnarrResponse" name="returnarrResponse" /> 
  </wsdl:operation>
- <wsdl:operation name="echo">
  <wsdl:input message="intf:echoRequest" name="echoRequest" /> 
  <wsdl:output message="intf:echoResponse" name="echoResponse" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="service1SoapBinding" type="intf:service1">
  <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="returnarr">
  <wsdlsoap:operation soapAction="" /> 
- <wsdl:input name="returnarrRequest">
  <wsdlsoap:body namespace="http://DefaultNamespace" use="literal" /> 
  </wsdl:input>
- <wsdl:output name="returnarrResponse">
  <wsdlsoap:body namespace="http://DefaultNamespace" use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
- <wsdl:operation name="echo">
  <wsdlsoap:operation soapAction="" /> 
- <wsdl:input name="echoRequest">
  <wsdlsoap:body namespace="http://DefaultNamespace" use="literal" /> 
  </wsdl:input>
- <wsdl:output name="echoResponse">
  <wsdlsoap:body namespace="http://DefaultNamespace" use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="service1Service">
- <wsdl:port binding="intf:service1SoapBinding" name="service1">
  <wsdlsoap:address location="http://127.0.0.1:8080/axis/services/service1" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>




-----------------------------------------------------------------------------
Response on wire
------------------------------------------------------------------------------
?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
  <echoResponse xmlns="http://DefaultNamespace">
   <echoReturn xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    <item xmlns="">1</item>
    <item xmlns="">2</item>
   </echoReturn>
  </echoResponse>
 </soapenv:Body>
</soapenv:Envelope>



And finally the .NET Client works
The problem now is that the client stubs generated with this wsdl for axis are incorrect

-----------------------------------------------------------------------
Client stub for axis
-----------------------------------------------------------------------
/**
 * Service1.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.2dev Aug 18, 2003 (10:57:46 IST) WSDL2Java emitter.
 */

package DefaultNamespace;

public interface Service1 extends java.rmi.Remote {
    public DefaultNamespace.Bean1 returnarr() throws java.rmi.RemoteException;
    public org.xmlsoap.schemas.soap.encoding.EchoReturn echo() throws java.rmi.RemoteException;
}
-----------------------------------------------------------------
Echoreturn.java
---------------------------------------------------------------
/**
 * EchoReturn.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.2dev Aug 18, 2003 (10:57:46 IST) WSDL2Java emitter.
 */

package org.xmlsoap.schemas.soap.encoding;

public class EchoReturn  implements java.io.Serializable {
    private int[] item;

    public EchoReturn() {
    }

    public int[] getItem() {
        return item;
    }

    public void setItem(int[] item) {
        this.item = item;
    }

    public int getItem(int i) {
        return item[i];
    }

    public void setItem(int i, int value) {
        this.item[i] = value;
    }

    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof EchoReturn)) return false;
        EchoReturn other = (EchoReturn) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.item==null && other.getItem()==null) || 
             (this.item!=null &&
              java.util.Arrays.equals(this.item, other.getItem())));
        __equalsCalc = null;
        return _equals;
    }

    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getItem() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getItem());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getItem(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        __hashCodeCalc = false;
        return _hashCode;
    }

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

    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "echoReturn"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("item");
        elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "item"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "int"));
        elemField.setMinOccurs(0);
        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);
    }

}


-----------------------------------------------------------------------
-----------------------------------------------------------------------


Can you please provide leads as to how to correct this problem




-----Original Message-----
From: Anne Thomas Manes [mailto:anne@manes.net]
Sent: Tuesday, September 30, 2003 9:45 PM
To: axis-user@ws.apache.org
Subject: RE: Axis using wrong encoding for array in Doc/literal


.NET is throwing an error because the WSDL response message definition 
doesn't match the structure of the returned message. The WSDL says that the 
message looks like this:

<wsdl:message name="returnarrResponse">
     <wsdl:part element="intf:returnarrResponse" name="parameters"/>
</wsdl:message>

where intf:returnResponse looks like this:
  <element name="returnarrResponse">
    <complexType>
      <sequence>
         <element name="returnarrReturn" type="impl:bean1"/>
      </sequence>
    </complexType>
</element>

and impl:bean1 looks like this:
  <complexType name="bean1">
    <sequence>
       <element name="a" type="xsd:int"/>
       <element name="myArr" nillable="true" type="xsd:int"
            minOccurs="0" maxOccurs="unbounded"/>
     </sequence>
  </complexType>

This looks like a very nice doc/literal definition. Note that this 
definition doesn't use the SOAP encoding-based ArrayOf_xsd_it datatype.

On the wire, though, Axis is in fact returning the ArrayOf_xsd_int type:
  <complexType name="ArrayOf_xsd_int">
    <complexContent>
      <restriction base="soapenc:Array">
         <attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:int[]"/>
      </restriction>
    </complexContent>
  </complexType>