Which attributes should you include in Target 1, Target…

DRAG DROP
An application serializes and deserializes XML from streams. The XML streams are in the following format:

The application reads the XML streams by using a DataContractSerializer object that is declared by the
following code segment:

You need to ensure that the application preserves the element ordering as provided in the XML stream.
You have the following code:

Which attributes should you include in Target 1, Target 2 and Target 3 to complete the code? (To answer, drag
the appropriate attributes to the correct targets in the answer area. Each attribute may be used once, more than
once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:

DRAG DROP
An application serializes and deserializes XML from streams. The XML streams are in the following format:

The application reads the XML streams by using a DataContractSerializer object that is declared by the
following code segment:

You need to ensure that the application preserves the element ordering as provided in the XML stream.
You have the following code:

Which attributes should you include in Target 1, Target 2 and Target 3 to complete the code? (To answer, drag
the appropriate attributes to the correct targets in the answer area. Each attribute may be used once, more than
once, or not at all. You may need to drag the split bar between panes or scroll to view content.)
Select and Place:

Answer:

Explanation:
DataContractSerializer DataContract DataMember
Target 1: [DataContract(NameSpace=http://contoso.com/2012/06)]
Target 2: [DataMember(Order=10)]
Target 3: [DataMember]

Target 1: The DataContractAttribute.Namespace Property gets or sets the namespace for the data contract for
the type. Use this property to specify a particular namespace if your type must return data that complies with a
specific data contract.
Target2, target3: We put Order=10 on FirstName to ensure that LastName is ordered first.
Note:
The basic rules for data ordering include:
* If a data contract type is a part of an inheritance hierarchy, data members of its base types are always first in
the order.
* Next in order are the current type’s data members that do not have the Order property of the
DataMemberAttribute attribute set, in alphabetical order.
* Next are any data members that have the Order property of the DataMemberAttribute attribute set. These are
ordered by the value of the Order property first and then alphabetically if there is more than one member of a
certain Order value. Order values may be skipped.
Data Member Order
https://msdn.microsoft.com/en-us/library/ms729813(v=vs.110).aspx
DataContractAttribute.Namespace Property
https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.namespace
(v=vs.110).aspx



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Joseph

Joseph

Correct answer

Bill

Bill

per this description of the DataMember Order : https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/data-member-order

The given answer for Target 2 and 3 would result in LastName getting Serialized in front of the Firstname, violating one of the requirements to maintain the order of the elements.

They could be reversed and be correct; the element names are alphabetical, so target 2 and 3 could also both be [DataMember] and be fine and the could also both be [DataMember Order=10] as well.

In the link I give above, check out cat and dog, have no order specified, it is shown before anything else except the base data member (zebra) added at the declaration.

This is the process logic as I understand it from the MS description:
First: Base Data Member (if provided)
Second: No Order Specified – List all alphabetically
Third: Order specified – List by Order, following all NoOrderItems. *IF Multiple items with same Order, they are grouped by Order listed alphabetically.