Skip to content

Instantly share code, notes, and snippets.

@BenjaminAdams
Created July 6, 2016 16:15
Show Gist options
  • Save BenjaminAdams/0956df5c456354a65dabea8bdd108a88 to your computer and use it in GitHub Desktop.
Save BenjaminAdams/0956df5c456354a65dabea8bdd108a88 to your computer and use it in GitHub Desktop.
How to add HTTP headers in a WCF service call
public void PerformSoapCall() {
using (var client = new SomeClient())
using (new OperationContextScope(client.InnerChannel))
{
HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
requestMessage.Headers["Authorization"] = "Basic 521vYmFsUGF5bWVudEdhdGV3YXk6R1BHMTIz22==";
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;
var res = await client.SomethingAsync();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment