Yes, Im pretty much doing the same thing, begin...commit/ rollback...dispose.
If I run my WCF service with ASP.Net compatibility turned on, and use "web" as my SessionContext, would that be a better scenario? Or should I be sticking with "call"? On 12 Nov, 18:30, Jason Meckley <[email protected]> wrote: > my first guess is that you never unbind the session from the context. > i would that there. if that doesn't work I would then browser the > ICurrentSessionContext implementations to see which is best suited for > your scenario. > > finally, there is also the issue of managing the scope of the session. > I have worked with NH in 3 contexts. > Web > Service Bus > ThreadPool.QueueWorkItem() > > with the web i open a transaction and session when a request begins > and commit/rollback and dispose of the session when the request ends. > combined with the post-redirect-get model for processing command > quests I haven't had an issue yet. > with a service bus it's similar. open a transaction and session when a > message is received and commit/rollback and dispose of the session > when processing the message has completed. > thread pool is a little trickier to explain. the code may be more > useful > ThreadPool.QueueWorkItem(item => { > using(var session = factory.OpenSession()) > using(var tx = session.BeginTransaction()) > { > CurrentSessionContext.Bind(session); > item(); > tx.Commit(); > CurrentSessionContext.Unbind(factory); > } > > }); > > On Nov 12, 12:36 pm, Andyk <[email protected]> wrote: > > > > > Hi, > > can anyone tell me which sessioncontext should be used in a Wcf > > environment. > > Currently I have a web application calling a WCF service, hosted in > > IIS. The WCF service does all the work and uses NHibernate. > > > I am using sessioncontext in a static class to manage nhibernate > > session like this: > > > public static ISession GetCurrentSession() > > { > > if (!CurrentSessionContext.HasBind(SessionFactory)) > > { > > CurrentSessionContext.Bind(SessionFactory.OpenSession > > ()); > > } > > return SessionFactory.GetCurrentSession(); > > } > > > and in the config I have: > > <property name="current_session_context_class">call</property> > > > When multiple users access the system, exceptions start being thrown, > > such as "Session is closed". Which gives me the impression the session > > is being shared, and isnt unique to each request. > > > Currently, for each WCF function, Im calling: > > NhibernateHelper.BeginTransaction(); > > // Do work > > NHibernateHelper.CommitTransaction(); > > NHibernateHelper.DisposeSession(); > > > There's something Im doing wrong, but Im racking my brains trying to > > find the solution. > > > Any response gratefully appreciated. > > > Andy --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
