Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Borrowing from many places but mostly:</p> <p><a href="http://msmvps.com/blogs/paulomorgado/archive/2007/04/27/wcf-building-an-http-user-agent-message-inspector.aspx" rel="nofollow">http://msmvps.com/blogs/paulomorgado/archive/2007/04/27/wcf-building-an-http-user-agent-message-inspector.aspx</a></p> <p>I simplified but I think I have an implementation that will add custom httpheaders.</p> <pre><code> public class HttpHeaderMessageInspector : IClientMessageInspector { private readonly Dictionary&lt;string, string&gt; _httpHeaders; public HttpHeaderMessageInspector(Dictionary&lt;string, string&gt; httpHeaders) { this._httpHeaders = httpHeaders; } public void AfterReceiveReply(ref Message reply, object correlationState) { } public object BeforeSendRequest(ref Message request, IClientChannel channel) { HttpRequestMessageProperty httpRequestMessage; object httpRequestMessageObject; if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject)) { httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty; foreach (var httpHeader in _httpHeaders) { httpRequestMessage.Headers[httpHeader.Key] = httpHeader.Value; } } else { httpRequestMessage = new HttpRequestMessageProperty(); foreach (var httpHeader in _httpHeaders) { httpRequestMessage.Headers.Add(httpHeader.Key, httpHeader.Value); } request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage); } return null; } } internal class HttpHeadersEndpointBehavior : IEndpointBehavior { private readonly Dictionary&lt;string,string&gt; _httpHeaders; public HttpHeadersEndpointBehavior(Dictionary&lt;string, string&gt; httpHeaders) { this._httpHeaders = httpHeaders; } public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { var inspector = new HttpHeaderMessageInspector(this._httpHeaders); clientRuntime.MessageInspectors.Add(inspector); } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { } public void Validate(ServiceEndpoint endpoint) { } } </code></pre> <p>Then after newing up my service reference:</p> <pre><code> var httpHeaders = new Dictionary&lt;string, string&gt;(); httpHeaders.Add("header1", "value1"); httpHeaders.Add("header2", "value2"); _serviceRef.Endpoint.Behaviors.Add(new HttpHeadersEndpointBehavior(httpHeaders)); </code></pre> <p>Nothing else had to change. If you think of a simpler way, let me know.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload