0
votes

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.

2
WCF is not HTTP nor ASP.NET - what do you need from the HttpContext?? In WCF, you should use the OperationContext instead.marc_s
Thanks for advice, but I don't see how can I check required thing with OperationContext (see original question updated).Budda
Don't sweat using the HttpContext. While WCF is designed to be protocol and host agnostic, there's nothing wrong with creating a service that's only meant to be used via HTTP and ASP.NET. You're not doing anything wrong by using HttpContext.Samuel Meacham
Samuel, I also think in the same way: so the question: why HttpContext.Current is null for a 2nd request? Do you have any idea? Thanks.Budda

2 Answers

1
votes

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.

0
votes

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.