What is use of message contract? [Resolved]

Posted by Rajeshatkiit under WCF on 12/19/2015 | Points: 10 | Views : 296 | Status : [Member] | Replies : 1
What is use of message contract? Is any body has used in their project?
Please explain with respect to project which you have handled?


Posted by: Rajnilari2015 on: 12/19/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 50


If we need to intercept the SOAP message that is passed between service and client, we need Message Contract which provides complete control over the SOAP message. It is a structural contract.


[MessageContract(IsWrapped = false)]

public class EmployeeInfoRequest
public string AuthCode;

public int EmployeeId;

public string EmployeeName;

[MessageContract(IsWrapped = false)]
public class EmployeeInfoResponse
public EmployeeInfo EmpInfo;

public interface IEmployeeService
EmployeeInfoResponse GetAllEmployeeInfo(EmployeeInfoRequest empInfo);

public class EmployeeService : IEmployeeService
public EmployeeInfoResponse GetAllEmployeeInfo(EmployeeInfoRequest empInfo)
//Validation Check
if (empInfo.bearerToken != "hPOCxaXYeNJsIqG4PNYzNa9BvWy37dgvbtZQZ2qYE79R-7l3j-Skhwj0xDLgONd")
//unauthorised bad request

return BadRequest();
// authorized code
return valid EmployeeInfoResponse ;

In the above piece of code we are using the SOAP message header for storing the bearer token / authentication code while calling the service method. It is needed for a valid Employee authentication for accessing the other assets/methods/services of the Employees. In such a scenario, SOAP message header is the most secure place to do so.

Also DNF has a very nice article on the same available at

Hope this will be helpful.


Thanks & Regards,
RNA Team

Rajeshatkiit, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response