2 Replies Latest reply on Aug 4, 2009 2:25 PM by ecchuckles

    how to get flex web services to properly serialize an array of objects?

    ecchuckles Level 1

      good day,

           I'm trying to use flex 3 web services to send/recieve an array of objects defined in the wsdl as a dynamic array like this:

            
      <schema targetNamespace="urn:wroc"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:ns="urn:wroc"
        xmlns="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="unqualified"
        attributeFormDefault="unqualified">
        <import namespace="http://schemas.xmlsoap.org/soap/encoding/" schemaLocation="http://schemas.xmlsoap.org/soap/encoding/"/>
        <complexType name="ArrayofWrocs">
         <sequence>
          <element name="item" type="ns:wroc" minOccurs="0" maxOccurs="unbounded" nillable="false"/>
         </sequence>
        </complexType>
        <complexType name="wroc">
         <sequence>
           <element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
           <element name="id" type="xsd:string" minOccurs="1" maxOccurs="1"/>
           <element name="value" type="xsd:string" minOccurs="1" maxOccurs="1"/>
           <element name="wrocs" type="ns:ArrayofWrocs" minOccurs="1" maxOccurs="1" nillable="true"/>
         </sequence>
        </complexType>
      </schema>

      </types>


      <message name="initWrock">
      <part name="name" type="xsd:string"/>
      <part name="type" type="xsd:string"/>
      <part name="value" type="xsd:string"/>
      <part name="wrocs" type="ns:ArrayofWrocs"/>
      </message>

       

      <message name="initWrockResponse">
      <part name="wroc" type="ns:wroc"/>
      </message>

       

      <portType name="wrocPortType">
      <operation name="initWrock">
        <documentation>Service definition of function ns__initWrock</documentation>
        <input message="tns:initWrock"/>
        <output message="tns:initWrockResponse"/>
      </operation>
      </portType>

       

      <binding name="wroc" type="tns:wrocPortType">
      <SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <operation name="initWrock">
        <SOAP:operation style="rpc" soapAction=""/>
        <input>
           <SOAP:body use="encoded" namespace="urn:wroc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </input>
        <output>
           <SOAP:body use="encoded" namespace="urn:wroc" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
      </operation>
      </binding>

       

       

      This wsdl was generated from gsoap using its convention for dynamic arrays which in my case is ArrayofWrocs.  In my script

      I've created an array of wrocs and checked to see if they have values but when I make the web service call, the arrayofWrocs

      has the right number of elements (2) but the objects are not expanded here is the trace output:

       


        body = "<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><ns:initWrock xmlns:ns="urn:wroc"><name xsi:type="xsd:string">hello</name><type xsi:type="xsd:string">world</type><value xsi:type="xsd:string">3</value><wrocs xsi:type="ns:ArrayofWrocs"><item xsi:type="ns:wroc"/><item xsi:type="ns:wroc"/></wrocs></ns:initWrock></SOAP-ENV:Body></SOAP-ENV:Envelope>

       

      on the response I get this error:

      Type Coercion failed: cannot convert mx.collections::ArrayCollection@275acb01 to Array

       

      but the data is bad with an array of empty wrocs. the service takes the args and returns it as a wroc:

      <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="urn:wroc"><SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><ns:initWrockResponse><wroc><name>hello</name><id>world</id><value>3</value><wrocs><item><name></name><id></id><value></value><wrocs></wrocs></item><item><name></name ><id></id><value></value><wrocs></wrocs></item></wrocs></wroc></ns:initWrockResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

       

      thanks in advance