none
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"); 
    OperationContext.Current.OutgoingMessageHeaders.Add(header);

    With this I also want to add

        xmlns:wsa="http://www.w3.org/2005/08/addressing"    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

Answers

  • 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 = "http://www.w3.org/2005/08/addressing

    x.wsa = "1";   

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

                MessageHeader securityTokenHeader

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

                OperationContext.Current.OutgoingMessageHeaders.Add(securityTokenHeader);

     

     


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