HttpContext.Current.Session is null when using PollingDuplexServiceHostFactory


  • I'm trying to get WCF Duplex services working in Silverlight 3.0 Beta 1.  I've been following the directions at, and I've run into a bit of an issue.  One of the things I want to do is to store the user's login information in a session variable server-side, i.e., something like this:

            public bool Login(string userID, string password)
                RegisteredUser user = (RegisteredUser)GetUser(userID);
                if (user != null)
                    if (user.Authenticate(password))
                        HttpContext.Current.Session.Add("user", user);
                        return true;
                return false;

    That bit of code worked fine initially, once I added this line to my web.config:

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

    But then I mucked things up by enabling duplex callbacks to Silverlight (3) clients.  The problem being that when you're using duplex services under Silverlight, you need to write your own service factory.  And as best as I can tell, when the service instance is created using the sample code that MS provides (, although ASP.NET compatibility is supposedly maintained (i.e., ServiceHostingEnvironment.AspNetCompatibilityEnabled returns true), HttpContext.Current.Session is always null.

    Any suggestions on how to enable session state in this scenario, other than to write my own session provider?

    Monday, May 25, 2009 3:02 AM


  • See



    Tuesday, May 18, 2010 9:02 AM

All replies

  • I have same problem.

    Are there anyone help about this?



    Sunday, August 16, 2009 8:49 AM
  • For what it's worth, my workaround was to forget about using the built-in HTTP cache, and use my own implementation. That'll work if the only thing you're interested in is caching; it's a bit more difficult if you need to access other portions of the ASP.NET stack. Sorry I don't have a better answer -- I'd be curious if anyone else does.

    And for what it's worth, I eventually had to abandon hosting my WCF service in IIS altogether -- see this post here for details:
    Sunday, August 16, 2009 11:21 PM
  • Hi,

    i have the same problem. On server-side service implementation i need to retrieve information stored in session variables, but HttpContext.Current.Session is always null. I did a simple test with a WCF service, and using PollingDuplexHttpBinding the session is always null whereas if i remove it i can access the session.

    Does anyone know if there's a way of building duplex service, using PollingDuplexHttpBinding, and be able to use the session state in the service methods?


    Tuesday, October 27, 2009 9:28 AM
  • I'm having the same problem.  At first HttpContext.Current was null.  I figured out all the flags and settings (aspNetCompatibilityEnabled and so on) to gain access to it only to find that HttpContext.Current.Session is null.

    Is this a bug that MS will be addressing or is there some technical reason we can't access Session when using the PollingDuplexBindingElement?

    Monday, January 11, 2010 3:26 PM
  • This is expected right now because some implementation detail of polling duplex channel. Basically we will reply the client application message with an empty http 200 before the service code is invoked. When the service code is invoked, the session property of httpcontext.current becomes null because the http request has been replied. I'm still investigating possible workarounds and will update here soon.



    Joe Zhou

    WCF silverlight team

    Friday, April 16, 2010 8:56 PM
  • Mine is not just Session that is null but HttpContext.Current IS null !
    and I'm just using a sinple WCF service, OperationContract


    Sunday, May 09, 2010 9:14 AM
  • See



    Tuesday, May 18, 2010 9:02 AM
  • By adding :


    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    as attribute of my WCF service class and

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />


    in the Web.Config, in System.serviceModel section it solved the problem.  Thank you


    Wednesday, May 19, 2010 5:32 PM
  • T_T

    I encountered the same problem!

    Monday, August 29, 2011 5:37 AM