I\'m working on a Windows Form application and there\'s a WCF service that needs to be called. I need to add a header (authorization - custom) to the request before it\'s se
The simplest way is to add it on the client side:
using (MyServ.ServiceClient proxy = new MyServ.ServiceClient())
{
using (new System.ServiceModel.OperationContextScope(proxy.InnerChannel))
{
MessageHeader head = MessageHeader.CreateHeader("Authorization", "http://yournamespace.com/v1", data);
OperationContext.Current.OutgoingMessageHeaders.Add(head);
}
}
and retrieve it on the server side:
string auth = OperationContext.Current.IncomingMessageHeaders.
GetHeader("Authorization", "http://mynamespace.com/v1");
I also suggest that you check these articles:
Authorization Header is missing in Http request using WCF
WCF Service with wsHttpBinding - Manipulating HTTP request headers