Access Session in WCF service from WebHttpBinding

前端 未结 2 1937
温柔的废话
温柔的废话 2021-01-05 15:28

I\'m using WCF service (via WebGet attribute).

I\'m trying to access Session from WCF service, but HttpContext.Current is null

I added AspNetCompatibilityReq

相关标签:
2条回答
  • 2021-01-05 15:47

    Yes, it is possible. If you edit the web.config:

    <system.serviceModel>
       <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    </system.serviceModel>
    

    and add the AspNetCompatiblityRequirements, the HttpContext.Current should be available.

    Check everything once again, maybe you've put the attribute in the wrong place (the interface instead of the class?).

    0 讨论(0)
  • 2021-01-05 15:54

    A RESTfull service with a session?

    See excellent discussion here: Can you help me understand this? "Common REST Mistakes: Sessions are irrelevant"

    http://javadialog.blogspot.co.uk/2009/06/common-rest-mistakes.html (point 6)

    and

    http://www.peej.co.uk/articles/no-sessions.html

    Quote from Paul Prescod:

    Sessions are irrelevant.

    There should be no need for a client to "login" or "start a connection." HTTP authentication is done automatically on every message. Client applications are consumers of resources, not services. Therefore there is nothing to log in to! Let's say that you are booking a flight on a REST web service. You don't create a new "session" connection to the service. Rather you ask the "itinerary creator object" to create you a new itinerary. You can start filling in the blanks but then get some totally different component elsewhere on the web to fill in some other blanks. There is no session so there is no problem of migrating session state between clients. There is also no issue of "session affinity" in the server (though there are still load balancing issues to continue).

    0 讨论(0)
提交回复
热议问题