Adding custom headers to a WCF message - Jan CTP

Tags: .NET, CodeSnippets, WinFX, WinFX January 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.

2 Comments

  • Guy Burstein said

    Why don't you move up to Feb CTP? There are a lot of breacking changes made, and the object model is much more close to the final version (Although internal sources tell me that there are some more breaking changes in the next CTP...)

  • Avner Kashtan said

    The project started with the January CTP, and we don't want to be constantly jumping from CTP to CTP.
    The idea is to jump CTPs every two-three months at most. When IS the next CTP drop due, anyway?

Comments have been disabled for this content.