cdie
cdie

Reputation: 4534

Using ASP.NET session in WCF = Session lost every call

I'm trying to do a WCF webservice to post some data to clients. Clients has to authenticate before accessing data, so I've made a method to authenticate, method which sets some session variable. When I try to access this sessions variables in another method, they're always NULL (I've tried with WCF test client and a little Winforms test client).

I've already set aspNetCompatibilityEnabled="true" my web.config and add attribute to my Service class [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)].

this test :

if (HttpContext.Current.Session[CONST_SESSION_AUTHENTICATE] != null &&        (bool)HttpContext.Current.Session[CONST_SESSION_AUTHENTICATE] == true)

always refers to null session variable ...

What did I miss ?

Thanks

Upvotes: 0

Views: 2516

Answers (1)

Cosmin Vană
Cosmin Vană

Reputation: 1582

How do you call your service ? You must use the same service client object and allow cookies. The session will work only if the client sends back the cookie created by ASP .NET.

Here is an example:

http://stack247.wordpress.com/2011/03/09/enable-cookies-session-in-wcf-aspnetcompatibilityrequirements/

Upvotes: 1

Related Questions