Jach's personal blog

(Largely containing a mind-dump to myselves: past, present, and future)
Current favorite quote: "Supposedly smart people are weirdly ignorant of Bayes' Rule." William B Vogt, 2010

Flex Tip: SOAP Webservice POST calls with an XMLList

Here's a tip that may be obvious to some people, but it certainly wasn't to me. Let me set up my situation and explain how I solved it.

I have Java web services that communicate with my Flex client via SOAP with the interface defined by a WSDL. Some of the older methods simply use Strings as parameters and return values, with each side constructing / converting the strings manually. (It's pretty ugly.)

After a while of this ugliness we started migrating to object-based parameters and return values that get converted to XML on the Flex side and Java native objects on the server side, all done by Enunciate. This works swell for return values, e.g. suppose I have this Java class:

public class SessionInfo {
@XmlAttribute public int id;
@XmlAttribute public String connect_url;
@XmlAttribute public String user;
@XmlAttribute public String query;

If I return a single SessionInfo object, on the Flex side I'll get a SOAP response similar to (using e4x as the resultType):

<return id="3" connect_url="localhost" user="admin" query="" />

Not the greatest, but manageable. Furthermore, I can construct an ArrayList<SessionInfo> on the server side and return that, resulting in a series of <return /><return />'s. All very easy to put into a native Flex XML or XMLList object.

Trying to reverse this, though, resulted in a headache. Basically, I wanted to send up a list of XML objects. My service call looked like:

<mx:operation name="createServer" resultFormat="object" result="event.token.resultHandler(event);" fault="event.token.faultHandler(event);">


with intent to send up multiple <options /> tags. I tried sending an XMLList directly, that didn't work. My initial hack was to just rewrite the whole request in actionscript at the time of the query, but it was ugly and relied on namespace definitions:

service.createServer.request = XMLList(

"<ns0:createServer xmlns:ns0=\"\">" +
"<server_name>" + server_name + "</server_name>" +
"<wrapper_name>" + wrapper_name + "</wrapper_name>" +
options_list +

Ugly, bad. It's a special case, and if I have any other methods that want a list of objects I have to do the same thing. I have a general service delegate and this broke the generality. Anyway, after playing around some more today I discovered a solution. I tried sending up an Array of XML <options /> tags, and looking at the network transfer I saw the amount of tags go up! But they didn't have any data. So I converted each XML tag into an Object (so now I have {'id': 3, 'name': 'admin'} and so on) and sent up an array of Objects. Flex happily obliged to convert the objects to the proper XML, and now I'm happy. I hope this can help someone else.

Posted on 2010-09-17 by Jach

Tags: flex, programming, tips, xml


Trackback URL:

Back to the top

Back to the first comment

Comment using the form below

(Only if you want to be notified of further responses, never displayed.)

Your Comment:

LaTeX allowed in comments, use $$\$\$...\$\$$$ to wrap inline and $$[math]...[/math]$$ to wrap blocks.