Adding custom headers to a WCF message – Jan CTP

Guy Burstein, again, writes about adding custom headers to a call made by a WCF proxy.
This is all very nice and well, but his code only works with the Feb. CTP of WCF, while I’m still using January here.
The differences seemed subtle at first – his instantiation of the OperationContextScope passed the proxy to the constructor, but there is no such constructor in the January CTP.
Simply instantiating the OperationContextScope with no parameters and adding headers seemed to work, but those headers never made it to the server-side.

After much fussing and digging, it turns out that the headers were transferred, but the way to fetch them was obscure. I don’t know if this was a design change from Jan to Feb or maybe it was just a bug that was fixed, but instead of accessing the headers like this:

string myHeader = OperationContext.Current.IncomingMessageHeaders.GetHeader(“myHeader”, “myNS”);

we have to do it like this:

string myHeader = OperationContext.Current.RequestContext.RequestMessage.Headers.GetHeader(“myHeader”, “myNS”);

Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.