[DataMember] changes in September 2005 CTP
-- Galen
Galen Earl Murdock
Veracity Solutions, Inc.
Principal Software Developer
-- Galen
Galen Earl Murdock
Veracity Solutions, Inc.
Principal Software Developer
Actually, it seems that DataMemberAttribute.Order says something about the ordinal position of the member in the class.
So where did VersionAdded go? It's interesting to note that as long as IsRequired is false for new DataMembers, older proxies still work just fine. I wonder, then, if VersionAdded wasn't useful and was therefore removed?
-- Galen
Galen Earl Murdock
Principal Software Developer
Veracity Solutions, Inc.
Let’s assume that your Data Contract needs in a new version a new mandatory field. If this happens, you’re breaking the contract with your consumers. Old consumers should have knowledge of this change, and, unfortunately, old calls will not work anymore.
But this is just my opinion...
I set it to 2 on the fifth member of a class. Nothing changed except the svcutil proxy attributed it as 5. Can't see any real value yet.
-- Galen
In fact it is very usefull if you work at the message level. Order rules the message order of the DataMember. If you omit it, the framework will decide which is the best order for your data members. If you declare it, message will respect the order specified ONLY for those you did specify.
As an example:
If you have a data contract like
[DataContract()]
public class User{
[DataMember(Order=1)
public string UserName;
[DataMember()]
public string Address;
[DataMember(Order=3)
public string Address2;
[DataMember()]
public string Address3;
}
this can generate some little confusion. Nothing garantees that the message is having UserName as the 1st element. What you're saying is that UserName is before Address2. So the message can be:
<Address>My Address</Address>
<Address3>My Address3</Address3>
<UserName>My Name</UserName>
<Address2>My Address2</Address2>
This is because the framework first decides which is the best order to serialize the other arguments and then respects the order you did specified.
But... if you do specify order for all the data members, the framework will respect it.
As an example if you have:
[DataMember(Order = 1)]
public string UserName;
[DataMember(Order = 2)]
public string Address;
[DataMember(Order=3)]
public string Address2;
[DataMember(Order=4)]
public string Address3;
You will have this in your message:
<UserName>My Name</UserName>
<Address>My Address</Address>
<Address2>My Address2</Address2>
<Address3>My Address3</Address3>
When you use svcutil, it will use the same logic. If you rather use the data contract in the client side and then create a channel through channelfactory, it will the order specified in the data contract from the client side.
As a best practice, i would recommend that, if you work at the message level and if you specify the order of a member for any reason, you should specify the order of all members. But maybe other folks can give their opinion about this.
Hope it helps
Cheers
If you do not specify the order attribute, WCF sorts it via alphabetical order. Unlike ASMX and the XMLSerializer, the XMLFormatter of WCF respects the ordering.
Doing ordered access is actually faster than unordered access.
WCF doesnt do any schema validation, but just reading from the XmlReader in [DataMember] order.
My opinion is to allow me to have the option to turn off the ordering system if I choose to.
If you don't specify an order, we infer one from the type member names.
In either case, we read elements in order -- so the perf is the same if you set the order or not.
Hi Douglas, txs for the answer.
So, the order is only important for direct message handling, right ?