Head London

Collection serialization and SOAP

Friday 10th March 2006 at 7:48 pm

The other day I was using SOAP and C# to return an array of objects from a web service to a Flash client. On the server, each object of type SiteSectionEntity has a property ("Children") which is an IList of SiteSectionEntities. It's a pretty normal recursive structure, one level deep. My trouble was that the Children objects were being serialized like this: [code] true Some text here. ...more attributes here... [/code] I didn't want that. I tried putting an attribute declaration on to the Children property of the C# class, but it didn't quite work: [code] [XmlElement( "Children", typeof(SiteSectionEntity))]

public IList Children {

    get { return children; }
    set { children = value; }

}

[/code]

This resulted in a nearly-working SOAP response (it was almost correct but I needed an ArrayOfChildren).

After some head-scratching, I figured it out.

[code]

[XmlArray("Children")] [XmlArrayItem("SiteSectionEntity",typeof(SiteSectionEntity))]

public IList Children {

    get { return children; }
    set { children = value; }

}[/code]

This results in the structure I wanted, and my Flash client was happy. It looks like this: [code] − − true images/florida1.JPG test 2 90 84 0 0 0 1 13 − true images/florida3.JPG test 1 89 84 0 0 0 1 15 true This is a test to see whether a new menu order of the correct magnitude gets generated when a new object is created. images/carpa.JPG menu order test 2 84 -1 200 100 100 1 1 [/code]Hopefully this will help out somebody else who runs into the same problem.

2 comments so far.

  1. redbluevn says:

    Do you know how to compiler Flash in C#?
    Thanks

  2. Dave says:

    Hm, maybe my post wasn’t clear.

    I was using a C# web application on the server to return data to the Flash movie via a SOAP web service. The problem was that the data wasn’t coming back in the format I wanted it to.

    As far as I know, there is no way to write anything in C# and end up with a compiled SWF. There are only two compilers that will generate SWF bytecode:

    *first, the Macromedia compiler that comes with Flash
    *second, the MTASC compiler from http://www.mtasc.org This compiler is written in the OCAML language, but you use it just like you would the Macromedia one (sort of).

    Actionscript 2 is very much like C# in its syntax, though, so if you are a C# coder you wouldn’t have much trouble learning the language, although the component architecture and general environment can be a little crazy sometimes.

Leave a comment