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:
  1.     true Some text here.   ...more attributes here...   

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:
  1. [XmlElement( &quot;Children&quot;, typeof(SiteSectionEntity))]</p> <p>public IList Children {</p> <p>&nbsp;&nbsp;&nbsp; get { return children; }<br /> &nbsp;&nbsp;&nbsp; set { children = value; }</p> <p>}</p> <p>

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:
  1. </p> <p>[XmlArray(&quot;Children&quot;)] [XmlArrayItem(&quot;SiteSectionEntity&quot;,typeof(SiteSectionEntity))]</p> <p>public IList Children {</p> <p>&nbsp;&nbsp;&nbsp; get { return children; }<br /> &nbsp;&nbsp;&nbsp; set { children = value; }</p> <p>}

This results in the structure I wanted, and my Flash client was happy. It looks like this:

CODE:
  1.   &minus;  &minus;   true  images/florida1.JPG test 2 90 84 0 0 0  1 13  &minus;   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   

Hopefully this will help out somebody else who runs into the same problem.


2 Responses to “Collection serialization and SOAP”  

  1. 1 redbluevn

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

  2. 2 Dave

    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 Reply