Accessing a session in a WCF service from WebHttpBinding

I am using the WCF service (via the WebGet attribute).

I am trying to access a session from a WCF service, but HttpContext.Current is null

I added AspNetCompatibilityRequirements and edited the web.config file, but I still can’t access the session.

Can I use WebGet and Session together?

Thanks!

+6
source share
2 answers

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

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

and add AspNetCompatiblityRequirements , HttpContext.Current should be available.

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

+5
source

RESTfull service with session?

See an excellent discussion here: Can you help me figure this out? "General REST errors: sessions are out of date"

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

and

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

Quote from Paul Prescod:

Sessions do not matter.

The client will not need to "log in" or "start the connection." Authentication HTTP automatically with every message. Client applications are consumers of resources, not services. Therefore, there is nothing to log in to! Say you are booking a flight on the REST web service. You do not create a new "session" connection to the service. Rather, you ask for a "route creator" to create a new route for you. You can start filling in the blanks, but then you will get completely different components elsewhere on the Internet to fill in some other blanks. There is no session there, so there is no problem transferring session state between clients. There is also no problem with "session affinity" on the server (although there are still problems with load balancing).

+4
source

Source: https://habr.com/ru/post/898147/


All Articles