views:

82

answers:

3

OK, so this is the strangest issue in .net programming I have ever seen. It seems that object fields are serialized in .net web services in order of field initialization.

It all started with Flex not accepting SOAP response from .net web service. I have found out that it was due to the order of serialized fields was statisfying the order of fields in declared serializable class.

It had something to do with generic lists and LINQ to SQL but I can't find out what. This one is really hard to reproduce.

Example to get the idea:

[Serializable] 
public class SomeSample 
{ 
    public int A; 
    public int B; 
    public int C; 
} 

I was querying some data tables within asmx web service using linq and returning list of SomeSample objects:

var r = (from ...... select new SomeSample { A = 1, C = 3 }).ToList(); 

Now the list was once more iterated and B field was applied some value (ex. 2).

However the returned soap envelope contained following excerpt:

<A>1</A><C>3</C><B>2</B> 

Please notice the order of serialization. If I initially initialized all fields:

var r = (from ...... select new SomeSample { A = 1, B = 2, C = 3 }).ToList(); 

object was serialized in correct order.

I must add, that in both cases the debugger shows exactly the same content of "r" variable.

Am I losing my mind or is this normal behavior?

Thanks in advance.

A: 

I think you should not rely on serialization order. Actually it doesn't matter for correct deserialization.

Fedor
A: 

Yes it does. :-( At least for elements for SOAP deserializer in Flex SDK 3.6.0.x.

kubaw2
A: 

I meant in previous post, that -- no matter if it is OK with SOAP/WSDL specification -- Flex SDK expects

<sequence>

child elements to be provided in order as defined in WSDL.

kuba2