Reputation: 1491
I am trying to consume a WCF service that requires MessageHeaders to be present. I can create the Headers, and also call methods on the service
factory = new ChannelFactory<IMyService>("*");
proxy = factory.CreateChannel();
var ns = "http://www.myNamespace/...";
var header = MessageHeader.CreateHeader("Username", ns, "foo");
// Current is null <--
OperationContext.Current.OutgoingMessageHeaders.Add(header);
return proxy.CallMyMethod();
The problem is that the Current in OperationContext is null, so my question is how do I inject these headers in to the message please ?
Upvotes: 0
Views: 377
Reputation: 2366
Have you created object for OperationContext ?
try putting your Add header code in
using (OperationContextScope scope = new OperationContextScope(((IContextChannel) proxy))
{
// your code to add custom header
}
Hope it helps..!!!
Upvotes: 3