views:

52

answers:

2

There is a Silverlight (4.0) application that is calling to WCF-service. During 1st call to WCF-service some data are get from HttpContext.Current.Session object.

During 2nd call to WCF-service HttpContext.Current is null... Do you have any idea why (and how to fix that)?

Current settings:

  1. Options "aspNetCompatibilityEnabled" and "runAllManagedModulesForAllRequests" are set to true in the web.config,
  2. Service definition looks like this:

    [ServiceContract(Namespace = "")]

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

    public class ElitaDataService {

P.S. The purpose to use HttpContext from the WCF service is to check: a. if current user is logged (this information is stored in Session); b. if user works with own data (look only own order details, for example).

P.P.S. I saw that OperationContext is suggested to be used instead of HttpContext, but it's not clear what are properties in the OperationContext that would help to resolve items "a" and "b".

Please advise, thanks.

+1  A: 

So you have aspNetCompatibilityEnabled set to true in your web.config, but do you have this attribute on your [ServiceContract] class?

[AspNetCompatibilityRequirements(RequirementsMode =
    AspNetCompatibilityRequirementsMode.Allowed)]

(You could use Allowed or Required)

Just because the hosting application allows asp.net compatibility doesn't mean that the individual services have it turned on.

Samuel Meacham
Yes, this attribute is turned on.
Budda
A: 

It's a magic... now HttpContext.Current is non-null during each request... don't know why... If you know why that's possible - please let me know.

Budda