Sharing ASP.NET Session State With WCF Session
How can I share my asp.net session with wcf session .
Say I have a Session["UserId"] in my asp.net application . I want to access this inside the WCF Signature .
I enabled aspNetCompatibilityEnabled="true" in Webc开发者_如何学运维onfig & [ServiceContract(SessionMode=SessionMode.Required)]
in WCF.
I don't want to pass this session as an argument .
How can I achieve this?
You can't share an ASP.NET Session with WCF instance since they are in different Application Domains and could well be on different machines.
Here's a good article on Instance Context Sharing which will get you some way with "persistence session" in WCF. Then it's a question of passing shared data over the wire (or by using a common resource/database etc)
If you add this under <serviceModel>
in your Web.config, it will work.
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
It probably decreases performance a bit.
精彩评论