Which code segment should you use?

You are developing a Windows Communication Foundation (WCF) service that contains the following operation contract.

[OperationContract]
CustomerNames GetCustomerNames();

The operation returns customer names. You need to develop a definition for the operation contract that produces XML with the following structure.

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”>
<s:Header />
<s:Body>
<Names xmlns=http://tempuri.org/
xmlns:a=”http://schemas.microsoft.com/2003/10/Serialization/Arrays”
xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<a:string>Customer1</a:string>
<a:string>Customer2</a:string>
<a:string>Customer3</a:string>
</Names>
</s:Body>
</s:Envelope>

Which code segment should you use?

You are developing a Windows Communication Foundation (WCF) service that contains the following operation contract.

[OperationContract]
CustomerNames GetCustomerNames();

The operation returns customer names. You need to develop a definition for the operation contract that produces XML with the following structure.

<s:Envelope xmlns:s=”http://schemas.xmlsoap.org/soap/envelope/”>
<s:Header />
<s:Body>
<Names xmlns=http://tempuri.org/
xmlns:a=”http://schemas.microsoft.com/2003/10/Serialization/Arrays”
xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”>
<a:string>Customer1</a:string>
<a:string>Customer2</a:string>
<a:string>Customer3</a:string>
</Names>
</s:Body>
</s:Envelope>

Which code segment should you use?

A.
[MessageContract(IsWrapped = false)]
public class CustomerNames
{
[MessageBodyMember]
public string[] Names;
}

B.
[MessageContract(WrapperName = “”)]
public class CustomerNames
{
[MessageBodyMember]
public string[] Names;
}

C.
[DataContract]
public class CustomerNames
{
[DataMember]
public string[] Names;
}

D.
[DataContract]
public class CustomerNames
{
[DataMember(IsRequired = false)]
public string[] Names;
}

Explanation:
If the message contract is not wrapped, that is, if the property IsWrapped is set to false,
the message contract can have only one body part.

The name of the wrapper element for the request message contract must match the operation name.
Use the WrapperName property of the message contract for this.

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



Leave a Reply 1

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