Skip to content

Instantly share code, notes, and snippets.

@BenjaminAdams
Created July 6, 2016 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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