HttpContext.Current in WCF service during 2nd request

余生颓废 提交于 2019-12-13 04:11:45

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3162819/httpcontext-current-in-wcf-service-during-2nd-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!