What should you do to ensure that the client sends a SOAP body that is accepted by the service?

You have a Windows Communication Foundation (WCF) service that accepts the following message contract.

[MessageContract(WrapperNamespace=”http://www.movies.com”, ProtectionLevel=ProtectionLevel.None)]
public class Ticket
{
[MessageBodyMember(Namespace=”http://www.movietheater.com”, Order=1)]
public DateTime ShowTime = DateTime.Now;

[MessageBodyMember(Namespace=”http://www.movietheater.com”)]
public string ReservationName = “Smith”;

[MessageBodyMember(Namespace=”http://www.movietheater.com”)]
public int NumberOfSeats = 0;
}

You need to ensure that the client sends a SOAP body that is accepted by the service.

You have a Windows Communication Foundation (WCF) service that accepts the following message contract.

[MessageContract(WrapperNamespace=”http://www.movies.com”, ProtectionLevel=ProtectionLevel.None)]
public class Ticket
{
[MessageBodyMember(Namespace=”http://www.movietheater.com”, Order=1)]
public DateTime ShowTime = DateTime.Now;

[MessageBodyMember(Namespace=”http://www.movietheater.com”)]
public string ReservationName = “Smith”;

[MessageBodyMember(Namespace=”http://www.movietheater.com”)]
public int NumberOfSeats = 0;
}

You need to ensure that the client sends a SOAP body that is accepted by the service.

A.
<Ticket xmlns=”http://www.movies.com”>
<NumberOfSeats xmlns=”http://www.movietheater.com”>0</NumberOfSeats>
<ReservationName xmlns=”http://www.movietheater.com” />
<ShowTime xmlns=”http://www.movietheater.com”>2010-07-05T00:SI:10.0999304-05:00</ShowTime>
</Ticket>

B.
<Ticket xmlns=”http://www.movietheater.com”>
<ShowTime xmlns=”http://www.movietheater.com”>2010-07-05T00:51:10.0999304-05:00</ShowTime>
<ReservationName xmlns=”http://www.movietheater.com” />
<NumberOfSeats xmlns=”http://www.movietheater.com”>0</NumberOfSeats>
</Ticket>

C.
<Ticket xmlns=”http://wwv.movies.com”>
<ShowTime xmlns=”http://www.movietheater.com”>2010-07-05TOO:51:10.0999304-05:00</ShowTime>
<NumberOfSeats xmlns=”http://www.movietheater.com”>0</NumbecOfSeats>
<ReservationName xmlns=”http://www.movietheater.com” />
</Ticket>

D.
<Ticket xmlns=”http://www.movietheater.com”>
<ShowTime xmlns=”http://www.movietheater.com”>2010-07-05TOO:51:10.0999304-05:00</ShowTime>
<NumberOfSeats xmlns=”http://wwv.movietheater.com”>0</NumberOfSeats>
<ReservationName xmlns=”http://www.movietheater.com” />
</Ticket>

Explanation:
Using Message Contracts
(http://msdn.microsoft.com/en-us/library/ms730255.aspx)

MessageBodyMemberAttribute.Order Property
(http://msdn.microsoft.com/en-us/library/system.servicemodel.messagebodymemberattribute.order.aspx)

Order of SOAP Body Parts
In some circumstances, you may need to control the order of the body parts. The order of the body elements is alphabetical by default,
but can be controlled by the System.ServiceModel.MessageBodyMemberAttribute.Order property. This property has the same semantics
as the System.Runtime.Serialization.DataMemberAttribute.Order property, except for the behavior in inheritance scenarios
(in message contracts, base type body members are not sorted before the derived type body members).

EXAMPLE:
In the following example, amount would normally come first because it is first alphabetically. However, the Order property puts it into the third position.

[MessageContract]
public class BankingTransaction
{
[MessageHeader] public Operation operation;
[MessageBodyMember(Order=1)] public Account sourceAccount;
[MessageBodyMember(Order=2)] public Account targetAccount;
[MessageBodyMember(Order=3)] public int amount;
}
————————————————————————————-

Data Member Order
(http://msdn.microsoft.com/en-us/library/ms729813.aspx)

Example:
[DataContract]
public class BaseType
{

[DataMember]
public string zebra;
}
[DataContract]
public class DerivedType : BaseType
{
[DataMember(Order = 0)]
public string bird;
[DataMember(Order = 1)]
public string parrot;
[DataMember]
public string dog;
[DataMember(Order = 3)]
public string antelope;
[DataMember]
public string cat;
[DataMember(Order = 1)]
public string albatross;
}
Output
<DerivedType>
<!– Zebra is a base data member, and appears first. –>
<zebra/>

<!– Cat has no Order, appears alphabetically first. –>
<cat/>

<!– Dog has no Order, appears alphabetically last. –>
<dog/>

<!– Bird is the member with the smallest Order value –>
<bird/>

<!– Albatross has the next Order value, alphabetically first. –>
<albatross/>

<!– Parrot, with the next Order value, alphabetically last. –>
<parrot/>

<!– Antelope is the member with the highest Order value. Note that Order=2 is skipped –>
<antelope/>
</DerivedType>



Leave a Reply 5

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


e

e

Correct answer is A

from the link in the explaination:

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.

Igor

Igor

Besides what happend with the public string ReservationName = “Smith”; ?
The value “Smith” is no present in no one answer.

bob

bob

Yes A is right.

I think it is very nice job they put these suggestion on the web. However this make our case worse if the suggested answer is wrong.

Lyubomir Petrovski

Lyubomir Petrovski

OrderAttribute: Controls the order of each element in the schema. By default, if this property
is not set explicitly, the data members appear alphabetically, followed
by elements for which this property is set explicitly. The same rules are
used to apply ordering as are used with Data contracts.

It’s definitely A.