Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF REST WebHttpBinding cookie handling
    text
    copied!<p>The problem is WCF client doesn't respect server cookie (doesn't set it on the next request). Here is how I create the client:</p> <pre><code>WebChannelFactory&lt;IPostService&gt; factory = new WebChannelFactory&lt;IPostService&gt;( new WebHttpBinding() {AllowCookies = true}, new Uri("http://10.6.90.45:8081")); _proxy = factory.CreateChannel(); </code></pre> <p>Settings AllowCookies to false has no effect too.</p> <p>What I did for now is wrote a simple IClientMessageInspector to persist the server cookie between requests, but I really don't want to do this, there should be a way to handle cookie in a standard way.</p> <p>The custom inspector I'm using now, which is working as expected, but I'm looking for a "clean" solution:</p> <pre><code> public class CookieInspector : IClientMessageInspector { private string _cookie; public object BeforeSendRequest(ref Message request, IClientChannel channel) { if(_cookie != null &amp;&amp; request.Properties.ContainsKey("httpRequest")) { HttpRequestMessageProperty httpRequest = request.Properties["httpRequest"] as HttpRequestMessageProperty; if(httpRequest != null) { httpRequest.Headers["Cookie"] = _cookie; } } return null; } public void AfterReceiveReply(ref Message reply, object correlationState) { if (reply.Properties.ContainsKey("httpResponse")) { HttpResponseMessageProperty httpResponse = reply.Properties["httpResponse"] as HttpResponseMessageProperty; if(httpResponse != null) { string cookie = httpResponse.Headers.Get("Set-Cookie"); if (cookie != null) _cookie = cookie; } } } } </code></pre>
 

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