0

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?

amateur
  • 41,925
  • 62
  • 185
  • 308

2 Answers2

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
  • 73,473
  • 21
  • 178
  • 189
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

Community
  • 1
  • 1
dumbledad
  • 14,688
  • 20
  • 108
  • 248