1 Reply Latest reply on May 19, 2008 6:17 AM by laurent_pinson

    Difficulties to send multiple object in multiple object with SOAP (WebService)

    laurent_pinson
      Hi,

      I have a problem similar to this one: bug 12891 report
      I manage to send complex object from flex to web services server (i.e java axis2) but i got problems with Array including Array

      My method to send object is (and work perfectly with different operations):

      quote:

      public function updateProject(requestInfo:Array,proj:Project):void{
      webService.updateProject.endpointURI = endPointURI;
      webService.updateProject.resultFormat = "object";

      var sendArray:Array = new Array(requestInfo,proj.toArray());

      var token:AsyncToken = webService.updateProject.send.apply(null,sendArray);
      token.addResponder(responder);
      }


      The proj.toArray() method translates all my "Project" instance into an array :

      quote:

      public function toArray():Array{
      var array:Array = new Array();

      array['projectId'] = _id;
      array['name'] = _name;
      array['beginningDate'] = _dateBegin;
      array['endDate'] = _dateEnd;
      array['isClosed'] = _closed;
      array['participants'] = ProjectUtil.listCollaboToArray(_listCollabo);
      array['lots'] = ProjectUtil.listLotToArray(_listLot);
      array['leader'] = _leader.toArray();
      array['description'] = _description;
      array['client'] = _customer.toArray();

      return array;
      }


      You can find the WSDL part that may interested you at the end of this topic.

      The problem appears with "participants" and "lots" which are arrays of different depths. We will focus our attention only on "participants" for this topic. To attract people with a beautiful topic on this forum instead of a huge block full of codes that will frighten everyone and approximate the numbers of answer to this topic to 0, I will list my attempt to send a full Project instance through WSDL, nicely with the tools this forum offers.
      These attempts concern the ProjectUtil.listCollaboToArray() method.

      #### 1- using object containing 1 object to send 1 element in "participants" ####

      Here is the code:
      quote:

      static public function listCollaboToArray(arr:Array):Object{
      var node:Object = new Object();
      var participant:Object= new Object();

      var up:UserProject = arr[0] as UserProject;
      participant.beginningDate = up.dateBegin;
      participant.endDate = up.dateEnd;

      var collaborateur:Array = new Array();
      collaborateur['id'] = up.id;
      collaborateur['name'] = up.name;

      participant.collaborator = collaborateur;
      node.participant = participant;

      return node;
      }


      And here is the result:
      quote:

      ...
      <project>
      <projectId>3</projectId>
      <name>SuperProject</name>
      <beginningDate>2008-05-15Z</beginningDate>
      <endDate>2008-05-15Z</endDate>
      <isClosed>false</isClosed>
      <participants>
      <participant>
      <beginningDate>2008-05-16Z</beginningDate>
      <endDate>2008-05-16Z</endDate>
      <collaborator>
      <id>0</id>
      <name>prenom 0</name>
      </collaborator>
      </participant>
      </participants>
      ...


      It works fine but we send only one participant.

      #### 2- using array containing N objects to send N elements in "participants" ####

      Here is the code:
      quote:

      static public function listCollaboToArray(arr:Array):Array{
      var node:Array = new Array();
      for(var index:* in arr){
      var participant:Object= new Object();
      var up:UserProject = arr[index] as UserProject;
      participant.beginningDate = up.dateBegin;
      participant.endDate = up.dateEnd;

      var collaborateur:Array = new Array();
      collaborateur['id'] = up.id;
      collaborateur['name'] = up.name;

      participant.collaborator = collaborateur;
      node.push(participant);
      }
      return node;
      }


      And here is the result:
      quote:

      ...
      </requestInfo>
      <project>
      <projectId>3</projectId>
      <name>SuperProject</name>
      <beginningDate>2008-05-15Z</beginningDate>
      <endDate>2008-05-15Z</endDate>
      <isClosed>false</isClosed>
      <participants>
      <participant>
      <beginningDate xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
      <endDate xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
      <collaborator>
      <id>[object Object],[object Object],[object Object]</id>
      <name>[object Object],[object Object],[object Object]</name>
      </collaborator>
      </participant>
      </participants>
      ...


      It seems that with multiple objects, Object class is not a good idea.
      We can see another problem appearing, you will find out more in the next attempt

      #### 3- using array containing N Arrays to send N elements in "participants" ####

      Here is the code:
      quote:

      static public function listCollaboToArray(arr:Array):Array{
      var node:Array = new Array();
      for(var index:* in arr){
      var participant:Array= new Array();
      var up:UserProject = arr[index] as UserProject;
      participant['beginningDate'] = up.dateBegin;
      participant['endDate'] = up.dateEnd;

      var collaborateur:Array = new Array();
      collaborateur['id'] = up.id;
      collaborateur['name'] = up.name;

      participant['collaborator'] = collaborateur;
      node.push(participant);
      }
      return node;
      }


      And here is the result:
      quote:

      ...
      <project>
      <projectId>3</projectId>
      <name>SuperProject</name>
      <beginningDate>2008-05-15Z</beginningDate>
      <endDate>2008-05-15Z</endDate>
      <isClosed>false</isClosed>
      <participants>
      <participant>
      <beginningDate xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
      <endDate xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
      <collaborator>
      <id>,,</id>
      <name>,,</name>
      </collaborator>
      </participant>
      </participants>
      ...


      And here we are, I am completely stuck. I tried replacing Object with ObjectProxy and Array with ArrayCollection but it did exactly the same thing.
      The "arr" Array in my listCollaboToArray method contains 3 elements. Knowing that, if you take a look at the result you may have notice something:
      quote:


      <collaborator>
      <id>,,</id>
      <name>,,</name>
      </collaborator>


      "id" and "name" tags have 2 comas which means they have <something>,<something>,<something> i.e 3 values!!!
      So instead of having 3 participants, I have 1 participant containing 3 entities (who said Schizophrenia?) and that is why "beginningDate" and "endDate" have problems too.
      Is it a bug? something I didn't understand?

      I will give all my gratitude to anyone who can tell me what is wrong here and I thank everyone who read this topic until the end.

      Laurent Pinson
        • 1. Difficulties to send multiple object in multiple object with SOAP (WebService)
          laurent_pinson Level 1
          Ok, i found my error. As it may help people in the future, here 's the solution:

          The problem comes from Eclipse. When you use the WSDL IDE, if you set an occurrence on an alone element in a sequence, the occurrence will be set on the sequence and not the element.

          Consequently I was trying to send several element in One sequence whereas it was expecting one element per sequence (and so all the elements were considered as one).

          If someone who read me gets the same problem look what you have to do :

          Before
          <xsd:complexType name="ParticipantList">
          <xsd:sequence minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="participant" type="tns:Participant">
          </xsd:sequence>
          </xsd:complexType>

          after
          <xsd:complexType name="ParticipantList">
          <xsd:sequence>
          <xsd:element minOccurs="0" maxOccurs="unbounded" name="participant" type="tns:Participant"/>
          </xsd:sequence>
          </xsd:complexType>