How to add cookie to HttpTransportBindingElement

I have a WCF client that interacts with the WCF service (AspNetCompabilityMode works), and I would like to add a cookie (on the client) for every call to this web service.

I looked at the HttpTransportBindingElement , but I cannot find where to add my cookie - is it possible to add a cookie to the HttpTransportBindingElement or should I consider a different approach?

+6
cookies wcf
source share
3 answers

The method described at http://kennyw.com/indigo/153 is service-based. This means that you must make sure that all calls to your WCF service are made after the OperationContextScope object is created and before , which is intended for this. Otherwise, the cookie will never be added to the request.

If you are looking for a centralized solution for adding cookies manually for all outgoing HTTP requests made to the WCF service, take a look at this thread:

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/624fb3f9-222d-4795-9140-fe9ef3934361/

+2
source

http://megakemp.wordpress.com/2009/02/06/managing-shared-cookies-in-wcf/

Unlike other manuals presented in other answers, this one contains all the necessary information in one place in a well-structured form.

+3
source

You must set the allowCookies parameter to bind to false . This sounds strange, but explains why here:

http://kennyw.com/indigo/211

Once you do this, you must add the cookies yourself using the method described here:

http://kennyw.com/indigo/153

+2
source

All Articles