How To Implement A Message Contract in WCF ? | WCF Interview Question

, ,
Message contract can be applied to type using MessageContract attribute as shown above. We can add custom header and custom body by using MessageHeader and MessageBodyMember attribute respectively.

When EmployeeDetails type in the service operation is used as parameter then WCF will add an extra header call 'ID' to the SOAP envelope. It also add First_Name, Last_Name as an extra member to the SOAP Body.


[MessageContract]

public class EmployeeDetails

{

    [MessageHeader]

    public int ID;



    [MessageBodyMember]

    public string First_Name;

    

    [MessageBodyMember]

    public string Last_Name;

}