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
we have to do it like this:
string myHeader = OperationContext.Current.RequestContext.RequestMessage.Headers.GetHeader
Hope it helps.