Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Monday, September 24, 2012

MessageHeaderArray Attribute

Consider the Message contract type definition as shown below.
 
[MessageContract]
    public class Department
    {
        [MessageHeader]
        public string DepartmentID;
        [MessageHeader]
        public string DepartmentName;
        [MessageHeader]
        public Employees Employee();

    }
In this we are having array of Employee type as message header. When this converted to SOAP Header it looks as shown below.
<Department>
  <DepartmentID>PRO1243</DepartmentID>
  <DepartmentName>Production</DepartmentName>
  <Employees>
    <Employee>Sam</Employee>
    <Employee>Ram</Employee>
    <Employee>Raja</Employee>
  </Employees>
</Department>
Suppose you want to show the all employee detail in same level. We can use MessageHeaderArray attribute which will serialize the array element independently. If you use the MessageHeaderArray attribute of Employees, SOAP message will look as shown below.
<Department>
  <DepartmentID>PRO1243</DepartmentID>
  <DepartmentName>Production</DepartmentName>
  <Employee>Sam</Employee>
  <Employee>Ram</Employee>
  <Employee>Raja</Employee>
</Department>
Note: MessageHeaderArray Attribute is applicable only for Array, not for collection.

No comments:

Post a Comment