Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

wcf

wcf-client

I am adding a WCF custom header with the 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 an attribute to this Message header.

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

like image 917
Tanaji Kamble Avatar asked Mar 08 '11 04:03

Tanaji Kamble


1 Answers

I found solution. We have to Implement custome header, which is inhertied from MessageHeader class.

MessageHeader class does have method OnWriteStartHeader(). We can add xml namespaces in this method.

Also we have to override OnWriteHeaderContents() method and write xml or value we want as MessageHeader.

Once this is ready while adding message header in request.Header.Add() pass object of our custom header class.

Refer following links more details.

http://www.netframeworkdev.com/windows-communication-foundation/messageheader-serializer-how-to-use-attributes-52827.shtml

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/c2a39df8-3943-4c41-acca-6da8e96f0dff

like image 65
Tanaji Kamble Avatar answered Oct 22 '22 21:10

Tanaji Kamble