Is it possible to read cookies in the OperationContract of a wcf service? I am trying to read a cookie value in the contract method, but its always empty. If I read the same cookie from a .aspx page, the value is present. Any ideas?
Asked
Active
Viewed 1,230 times
0
-
Code, please. Hard to know what you're doing wrong when you don't show what you're doing. – John Saunders Sep 15 '10 at 18:17
2 Answers
1
How are you hosting them? WCF is intended to be host-neutral -- i.e. your services should still work when hosted outside of IIS. However, there is a compatibilty mode which might help you:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
The default value is false and disables most ASP.NET features like HttpContext.Current.

Kirk Woll
- 76,112
- 22
- 180
- 195
1
The BasicHttpBinding.AllowCookies Property may fix this, as mentioned at the start of Enrico's blog post on Managing shared cookies in WCF (referenced here). The post includes the web.config fragment:
<system.ServiceModel>
<bindings>
<basicHttpBinding allowCookies="true">
</bindings>
<client>
<endpoint address="http://localhost/myservice"
binding="basicHttpBinding"
contract="IMyService" />
</client>
</system.ServiceModel>
but no code fragment using it (the blog post has code for more complex solutions using the same cookies with different web services).
======== EDIT ==========
Or perhaps even allowCookies=false