Array Serialization in Flex

I have been doing a lot of Flex work over the last couple of weeks. I have to say, it is like a dream come true after having written my fair share of code in the Macromedia Flash IDE which is something akin to eating beans with a toothpick, you get there in the end but it is a long and arduous journey. FlexBuilder, built on Eclipse, is a fully featured IDE that relieves a lot of the frustration.

Anyway, back to the plot… Being a .NET developer at heart my first foray into Flex has been a front end that sits on top of some .NET web services. There are a few options as to what you put behind your Flex apps but .NET was the best fit for the job and my skills…

So off I went and all was going swimmingly until I tried to send an array of integers from the flex app to my .NET web service. The darn thing wouldn’t work. So I opened up (the excellent, probably worth another post) Service Capture and had a look at what was being submitted to the web service.

Flex, it appears, was serializing my int array like so:

<int>1,2,3,4,5</int>

My web service was expecting:

<int>1</int>
<int>2</int>
<int>3</int>
<int>4</int>
<int>5</int>

So what did I do? I spent a while looking around the FlexCoders Yahoo group. Could’t find exactly what I was after so I posted the problem…

The upshot is there seems to be a couple of serialization bugs that Adobe are planning to sort out in the imminent service update. Whether they are responsible for my problem I didn’t find out but here’s hoping.

In the meantime my options are to send literal XML to my web service rather than allow Flex to serialize it for me. This, I imagine will require some adjustments to the back end too although  I haven’t tried it yet and don’t really want to if I can help it, simply because I shouldn’t have to in this day and age.

There are various solutions I could implement on the server such as some sort of custom deserialization but this is all very complicated just so as I can pass an array of integers and  besides which, if this is due to a bug I’ll have to undo it all when it is fixed.

Another alternative suggested on the group was to use JSON. It turns out that there is a Flex JSON implementation and a .NET one, neither of which I had heard of before. Sam Shrefler explains… Thanks Sam that looks just the ticket.

Advertisements

11 Responses to “Array Serialization in Flex”


  1. 1 Sam Shrefler September 11, 2006 at 1:27 am

    No problem…Glad I could help. The real thanks should go to the Darron (JSON is AS) and the person that integrated JSON into .NET. Good luck with your project.

  2. 2 avejidah January 11, 2010 at 10:46 pm

    Waking the dead, but I found this on google after having similar issues. Here is how I solved the problem.

    $server->wsdl->addComplexType(
    ‘Colors’,
    ‘complexType’,
    ‘array’,
    ‘sequence’,
    ‘SOAP-ENC:Array’,
    array(),
    array
    (
    array(‘ref’ => ‘SOAP-ENC:arrayType’,
    ‘wsdl:arrayType’ => ‘xsd:string[]’)
    ),
    ‘xsd:string’
    );

    $server->register
    (
    ‘inTest’,
    array(‘params’ => ‘tns:Colors’),
    array(‘return’ => ‘xsd:string’),
    ‘http://mysite.com/services’
    );

    Works correctly. If you use the first array in the addComplexType instead of the second array, you’ll get Serialization.

    Here’s a struct with that array just as an example:

    $server->wsdl->addComplexType(
    ‘Flower’,
    ‘complexType’,
    ‘struct’,
    ‘sequence’,
    ”,
    array
    (
    ‘ScientificName’ => array(‘name’ => ‘ScientificName’, ‘type’ => ‘xsd:string’),
    ‘Colors’ => array(‘name’ => ‘Colors’, ‘type’ => ‘tns:Colors’)
    )
    );

    $server->register
    (
    ‘inTest’,
    array(‘params’ => ‘tns:Flower’),
    array(‘return’ => ‘xsd:string’),
    ‘http://mysite.com/services’
    );

  3. 3 avejidah January 11, 2010 at 10:50 pm

    var colors:Object = new Object();
    colors.Colors = new Array();
    colors.Colors[0] = ‘Red’;
    colors.Colors[1] = ‘Green’;
    colors.Colors[2] = ‘Blue’;
    colors.ScientificName = ‘Iris Testopoly’;

    wsTest.inTest(colors);

  4. 4 Nelson April 18, 2013 at 8:22 am

    We’re a bunch of volunteers and starting a new scheme in our community. Your web site provided us with helpful information to work on. You have done an impressive task and our entire group shall be grateful to you.

  5. 5 affordable life insurance for a family May 23, 2013 at 10:37 pm

    What’s Going down i’m new to this, I stumbled upon this I have found It positively useful and it
    has aided me out loads. I hope to contribute & help different users
    like its aided me. Good job.

  6. 6 how to make money June 5, 2013 at 3:10 pm

    hello, that’s a sweet post. i hope you will continue to choose this

  7. 7 Lilly June 12, 2013 at 1:58 pm

    a lot more to do with society’s pushing girls toward liberal arts opportunities in their formative many years. Blogger Bert Maes replied it best in his latest post (emphasis

  8. 8 for young drivers car insurance June 15, 2013 at 10:02 am

    I’m not that much of a internet reader to be honest but
    your blogs really nice, keep it up! I’ll go ahead and bookmark your site to come back in the future. All the best

  9. 9 http://www.getjealous.com July 22, 2013 at 6:37 pm

    I read this article fully about the difference of newest and
    earlier technologies, it’s remarkable article.

  10. 10 Juli August 2, 2013 at 6:28 am

    We stumbled over here different web page and thought I should check things out.

    I like what I see so now i’m following you. Look forward to exploring your web page again.

  11. 11 Georgina September 14, 2013 at 9:09 pm

    But then it is possible to also just keep adding tracks
    and recording onto them while listening (in headphones needless to say)
    to the earlier track(s) playing back. Here’s the right
    process of how you can hook up the surround sound
    speakers. With all with the cables running back with a central wiring panel,
    it’s easy to improve how and what every individual cable is connected to and
    how it’s used for.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: