views:

1127

answers:

2

I'm having a WCF client which communicates with a WCF service (running AspNetCompabilityMode), and I would like to add a cookie (on the client) to every call to this web service.

I have 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 another approach?

+1  A: 

You have to set the allowCookies configuration option for your binding to false. This sounds odd, but it is explained why here:

http://kennyw.com/indigo/211

Once you do that, you have to add the cookies yourself using the method described here:

http://kennyw.com/indigo/153

casperOne
A: 

The method described in http://kennyw.com/indigo/153 works on a per-service-call basis. This means you have to make sure all invocations to your WCF service are made after the OperationContextScope object is created and before it is disposed for this to work. Otherwise the cookie will never be added to the request.

If you are looking for a centralized solution to manually add a cookie to all outgoing HTTP requests made to the WCF service have a look at this thread:

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

Enrico Campidoglio