Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to I get the value of a custom soap header in WCF
    primarykey
    data
    text
    <p>I have created a custom soap header, and added it into my message via IClientMessageInspector</p> <pre><code> public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) { var header = new MessageHeader&lt;AuthHeader&gt;(); header.Content = new AuthHeader(Key); header.Actor = "Anyone"; var header2 = header.GetUntypedHeader("Auth", "xWow"); request.Headers.Add(header2); return null; } [DataContract(Name="Auth")] public class AuthHeader { public AuthHeader(string key) { this.Key = key; } [DataMember] public string Key { get; set; } } </code></pre> <p>I also have an IDispatchMessageInspector, and I can find the correct header in the list. However, there is no value. I know that the value went across the wire correctly, because the message string is correct</p> <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;s:Header&gt; &lt;Auth s:actor="Anyone" xmlns="xWow" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;Key xmlns="http://schemas.datacontract.org/2004/07/xWow.Lib"&gt;HERE IS MY KEY VALUE!!!!&lt;/Key&gt; &lt;/Auth&gt; &lt;To s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://localhost:26443/AuthService.svc&lt;/To&gt; &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://tempuri.org/IAuthService/GetPayload&lt;/Action&gt; &lt;/s:Header&gt; &lt;s:Body&gt; &lt;GetPayload xmlns="http://tempuri.org/"/&gt; &lt;/s:Body&gt; &lt;/s:Envelope&gt; </code></pre> <p>But there does not seem to be any property to retrieve this value. The MessageHeaderInfo class has Actor, etc, but nothing else useful I can find.</p> <p>On the client side I had to convert between Header and Untyped header, is there an equivalent operation on the server?</p> <p>I found the following, which should work.</p> <pre><code>request.Headers.FindHeader("Auth", "xWow"); request.Headers.GetHeader&lt;AuthHeader&gt;(index); </code></pre> <p>If I manually find the right index and call the second line, it works as expected. However FindHeader is returning -1 as the index, even though I have confirmed in the watch window that those are the correct values for the name and namespace.</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.
 

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