开发者

HttpContext.Current in WCF service during 2nd request

开发者 https://www.devze.com 2023-01-05 06:24 出处:网络
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.

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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消