Ask a Question related to Macromedia Flex General Discussion, Design and Development.
-
laurent pinson #1
Difficulties to send multiple object in multiple objectwith SOAP (WebService)
Hi,
I have a problem similar to this one:
[url]http://bugs.adobe.com/jira/browse/SDK-12891[/url]
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):
[Q] 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);
}[/Q]
The proj.toArray() method translates all my "Project" instance into an array :
[Q] 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;
}[/Q]
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
throught WSDL, nicely.
These attempts concern the ProjectUtil.listCollaboToArray() method.
#### 1- using object containing 1 object to send 1 element in
"participants" ####
Here is the code:
[Q] 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;
}[/Q]
And here is the result:
[Q] ...
<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>
... [/Q]
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:
[Q] 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;
}[/Q]
And here is the result:
[Q] ...
</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>
...[/Q]
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:
[Q] 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;
}[/Q]
And here is the result:
[Q] ...
<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>
...[/Q]
And here we are, I am completly stucked. 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:
[Q]
<collaborator>
<id>,,</id>
<name>,,</name>
</collaborator>[/Q]
"id" and "name" tags have 2 comas wich 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 would give all my gratitude to anyone who can tell me what is wrong here.
Laurent Pinson
<xsd:complexType name="Project">
<xsd:sequence>
<xsd:element name="projectId" type="xsd:int"></xsd:element>
<xsd:element name="name" type="xsd:string"></xsd:element>
<xsd:element name="beginningDate" type="xsd:date"></xsd:element>
<xsd:element name="endDate" type="xsd:date"></xsd:element>
<xsd:element name="isClosed" type="xsd:boolean"></xsd:element>
<xsd:element name="participants" type="tns:ParticipantList"></xsd:element>
<xsd:element name="lots" type="tns:LotList"></xsd:element>
<xsd:element name="leader" type="tns:Collaborator"></xsd:element>
<xsd:element name="description" type="xsd:string"></xsd:element>
<xsd:element name="client" type="tns:Client"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ParticipantList">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="participant" type="tns:Participant"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Participant">
<xsd:sequence>
<xsd:element name="beginningDate" type="xsd:date"></xsd:element>
<xsd:element name="endDate" type="xsd:date"></xsd:element>
<xsd:element name="collaborator" type="tns:Collaborator"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Collaborator">
<xsd:sequence>
<xsd:element name="id" type="xsd:int"></xsd:element>
<xsd:element name="name" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
laurent pinson Guest
-
how to send multiple checkboxes against a query toanother cfm
Hi, I am a new user....need some help. I have a query. I displayed different features for an acct#. Beside each feature, I want a checkbox type... -
Cannot send multiple SMS on two client simulators
Hi there, i am trying to run the example on the help file on how to send multiple sms (using 'submitMulti'). It is supposed to echo back the message... -
Q: serve multiple request in 1 SOAP message?
Hello, I would like to know if it's possible for .NET to handle multiple requests in a single SOAP message. I am under the impression that the... -
how to send objects with different namespaces to multiple Web Services
I have a problem where i would like to send the same object to 2 or more different webservices which accept objects with exactly the same... -
Send Object to webservice problem cast
Hi all, I have a class LiveSupportClass.Config public class Config : ISerializable -
laurent pinson #2
Re: Difficulties to send multiple object in multipleobject with SOAP (WebService)
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:element>
</xsd:sequence>
</xsd:complexType>
after
<xsd:complexType name="ParticipantList">
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="participant"
type="tns:Participant"></xsd:element>
</xsd:sequence>
</xsd:complexType>
laurent pinson Guest



Reply With Quote

