views:

785

answers:

2

I'm seeing a very strange issue with a .NET webservice being consumed by Flex.

I have a very simple class with nothing other than properties with [XmlAttribute('xxx')] attributes.

public class OrderAddress
{
    public OrderAddress() {}

    [XmlAttribute("firstName")]
    public string FirstName { get; set; }

    [XmlAttribute("lastName")]
    public string LastName { get; set; }

    [XmlAttribute("company")]
    public string Company { get; set; }        

    [XmlAttribute("address1")]
    public string Address1 { get; set; }

    ... (more properties)
}

The problem is that in Flex when this object is deserialized EVERY SINGLE fields is null in the debugger. The instance of the OrderAddress class is not null, just all the fields. I an 100% sure my web service proxy layer is up to date and there is 100% definitely data going across the wire as shown by Fiddler.

The very very wierd thing is that if I change one of these properties to serialize as an element (as opposed to XmlAttribute) and recompile ONLY my C# webservice then the data instantly can be recognized by Flex. If I add a completely unused field - like public string Foo = "foo"; then that also suddenly works.

I kind of remember seeing something like this before but don't remeber if I successfully fixed it or not.

Its 3:30am for me and I need to postpone my hardcore troubleshooting, but throwing this out here in case its obvious to anyone reading. The code is in a module, which I know can sometimes cause some wierdness - but this seems to be very wierd.

A: 

Elements centric XML is more interoperable format in XML serialization. This is the reason that the new WCF DataContract serializer serializes every property as elements instead of attribute. Attribute to me is descriptor to the element rather than data for the element.

codemeit
right! which is exactly why i am using an attribute. address fields are properties of an Address and by no means need any hierarchical structure. attributes work just fine, but why the absence of any elemnts makes a difference i still cannot figure out
Simon_Weaver
+1  A: 

After three days' struggling, finally I figured out this XML attribute was the cause of my problem. Slightly different from yours, my class has an array of objects in addition to the XML attribute. Flex was able to generate proxies, and even got attribute correctly (it was treated as a property), but it failed to deserialize the XML elements (returned from web serive) to array of objects. Once I delete that attribute, everything worked fine...so yes, this is "element centric XML serialization". But, is there any way to work around it?

NewFlexer
not sure if your situation was same as mine - but have you tried switching over to WCF instead of ASMX
Simon_Weaver