[DataMember] changes in September 2005 CTP

From looking at the September 2005 CTP docs, it would seem that DataMemberAttribute.IsOptional has been renamed to IsRequired and that the DataMemberAttribute.VersionAdded has been renamed to Order. Is the latter correct?

-- Galen
Galen Earl Murdock
Veracity Solutions, Inc.
Principal Software Developer

[318 byte] By [GalenMurdock] at [2008-2-13]
# 1

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.

GalenMurdock at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2
My opinion is that this was too confusing and unnecessary, so maybe the WCF team removed the property also considering the same. I think IsRequired property can handle all this, if your service doesn’t require new properties that did not exist in the past. If it does, then your contract must be changed.

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...

HugoBatista at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3
I was thinking along the same lines. How about DataMemberAttribute.Order? Anyone want to weigh in on its usefulness?

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

GalenMurdock at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 4

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

HugoBatista at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 5
I have blogged about this before here:
http://www.softwaremaker.net/blog/EnforcingOrderingOfDataElementsWhenReceivingMessagesInWCFIndigo.aspx

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.

Softwaremaker at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 6
So, if specifying the order is actually faster, a best practice would be to alway specify the order, right ?
HugoBatista at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 7
Yes, I would think so since it is not doing any schema validation.
Softwaremaker at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 8
Just to be clear.

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.

douglasp at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 9

Hi Douglas, txs for the answer.

So, the order is only important for direct message handling, right ?

HugoBatista at 2007-9-8 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified