Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOAP parameter serialization

rmarp
Level 2
Level 2
Hi all,



I'm looking for some information on how Flash/Flex serializes
parameters to WebService operations. If a web service operations
takes a simple parameter like a string, I can just pass it in as
the argument to the Operation.send() method but what if the
parameter is a "complexType"? Do I need to create an xml node or
just an object with public properties, etc...?



Any info on this would be much appreciated.



Ryan
3 Replies
aBill
Level 3
Level 3
Hi



For complex type you can pass the parameter in object. for
example:

WSDL type definition

<complexType name="SOAPStruct">

<sequence>

<element name="varString" nillable="true"
type="xsd:string" />

<element name="varInt" type="xsd:int" />

<element name="varFloat" type="xsd:float" />

</sequence>

</complexType>





_service.echoStruct({varString:'The String', varInt:245,
varFloat:2134.123});

or pass it through from tag declarion: for example

<mx:operation name="echoStruct" result="onResult(event)"
fault="onFault(event)">

<mx:request format="object">

<inputStruct>

<varString>The String</varString>

<varInt>245</varInt>

<varFloat>2134.123</varFloat>

</inputStruct>

</mx:request>

</mx:operation>



and you can also construct it as xml, for example

<mx:request format="xml">

<ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance">

<key
xsi:type="xsd:string">00000000000000000000000000000000</key>


<q
xsi:type="xsd:string">{ti_searchparm.text}</q>

<start xsi:type="xsd:int">0</start>

<maxResults xsi:type="xsd:int">10</maxResults>

<filter xsi:type="xsd:boolean">true</filter>

<restrict xsi:type="xsd:string" />

<safeSearch
xsi:type="xsd:boolean">false</safeSearch>

<lr xsi:type="xsd:string" />

<ie xsi:type="xsd:string">latin1</ie>

<oe xsi:type="xsd:string">latin1</oe>

</ns1:doGoogleSearch>

</mx:request>





Hope the above info help! Thanks!

William Chan
rmarp
Level 2
Level 2
William - Thank you, this is helpful. One other thing
though.. a few of the web service operations I need to call have a
parameter defined like this:



<complexType name="Account">

<sequence/>

<attribute name="Name" type="string" use="required"/>

<attribute name="Value" type="string" use="required"/>

</complexType>



Notice that the Name and Value items are attributes, not
sub-elements. If I create an object like:



var param:Object = {Name:"xxxx", Value:"yyyy"};



is there a way to have these properties encoded as attributes
as opposed to sub-elements?



Ryan
aBill
Level 3
Level 3
Ryan - you can just pass the object, flex does take care
where it is element or attribute



following is the sample(one of testcase we have)

<s:complexType name="Person">

<s:sequence>

<s:element minOccurs="1" maxOccurs="1" name="Age"
type="s:double" />

<s:element minOccurs="1" maxOccurs="1" name="ID"
type="s:float" />

</s:sequence>

<s:attribute name="Name" type="s:string" />

<s:attribute name="Male" type="s:boolean" />

</s:complexType>



var expected:Object = new Object();

expected.Name = "Bob Smith";

expected.Male = true;

expected.Age = 31;

expected.ID = 12345;

operation.send(expected);