Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Session in WCF service from WebHttpBinding

Tags:

asp.net

wcf

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

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

I added AspNetCompatibilityRequirements and edited web.config but I still cannot access session.

Is it possible to use WebGet and Session together?

Thank you!

like image 996
Jack Spektor Avatar asked Sep 27 '11 13:09

Jack Spektor


People also ask

How to use session in WCF?

WCF sessions have the following main conceptual features: They are explicitly initiated and terminated by the calling application (the WCF client). Messages delivered during a session are processed in the order in which they are received. Sessions correlate a group of messages into a conversation.

Can we use session in WCF service C#?

WCF manage session by creating the instance of the service class. These created instance(s) handle the incoming service request. In WCF, session is the way of managing the services instance(s) so that server can used these instances in an optimized way.


1 Answers

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?).

like image 189
Wiktor Zychla Avatar answered Nov 15 '22 06:11

Wiktor Zychla