You are developing a Windows Communication Foundation (WCF) service.
The service operation takes a customer number as the only argument and returns information about the customer.
The service requires a security token in the header of the message. You need to create a message contract for the service.
Which code segment should you use?
A.
[ServiceContract]
public interface IService
{
[OperationContract]
CustomerInformation GetCustomerInformation(Header header, int customerNumber);
}
[DataContract]
public class CustomerInformation
{
…
}
[MessageContract]
public class Header
{
[MessageHeader]
public string SecurityTag;
}
B.
[ServiceContract]
public interface IService
{
[OperationContract]
CustomerInformation GetCustomerInformation(Header header, int customerNumber);
}
[MessageContract]
public class CustomerInformation
{
…
}
[MessageContract]
public class Header
{
[MessageHeader]
public string SecurityTag;
}
C.
[ServiceContract]
public interface IService
{
[OperationContract]
CustomerInformation GetCustomerInformation(CustomerNumber request);
}
[DataContract]
public class CustomerInformation
{
…
}
[MessageContract]
public class CustomerNumber
{
[MessageHeader]
public string SecurityTag;
[MessageBodyMember]
public int CustomerNumberElement;
}
D.
[ServiceContract]
public interface IService
{
[OperationContract]
CustomerInformation GetCustomerInformation(CustomerNumber request);
}
[MessageContract]
public class CustomerInformation
{
…
}
[MessageContract]
public class CustomerNumber
{
[MessageHeader]
public string SecurityTag;
[MessageBodyMember]
public int CustomerNumberElement;
}
Explanation:
Using Message Contracts
(http://msdn.microsoft.com/en-us/library/ms730255.aspx)
Answer C & D is same
No, C and D are not same.
CustomerInformation is DataContract in C and MessageContract in D.
When you are using a MessageContract as a parameter to a Service Operation you must return void or another MessageContact i.e, Message and Data Contracts cannot be used together in one service operation.
So Correct Answer id D.
Hi Abhishek,
Have you appeared for exam 70-513