How to add attribute to WCF message header with MessageHeader.CreateHeader() method? RRS feed

  • Question

  • I am adding WCF custome header with following code

     MessageHeader header = MessageHeader.CreateHeader("Key", "ns", "Value"); 

    With this I also want to add

        xmlns:wsa=""    wsa:IsReferenceParameter="1" as attribute to this Mesage header.

    Is there any way to add above namespace and attribute to message header?

    Tuesday, March 8, 2011 5:03 AM


  • You can create a class with two attribute 

    public class XMLNSDesc{

    public string wsa; 

    public string IsReferenceParameter; 



    Then you can do this 


     OperationContextScope scope = new OperationContextScope(yourCLient.InnerChannel);

          XMLNSDesc x = new XMLNSDesc(); 

    x.wsa = "

    x.wsa = "1";   

                MessageHeader<XMLNSDesc > securityToken = new MessageHeader<XMLNSDesc >(x);

                MessageHeader securityTokenHeader

                    = securityToken.GetUntypedHeader("myToken", "x");




    Tanvir Huda
    • Marked as answer by Yi-Lun Luo Tuesday, March 15, 2011 9:17 AM
    Tuesday, March 8, 2011 6:13 AM