I have a WCF MSMQ service (hosted in a windows service). My method has the TransactionScopeRequired attribute on it.
I am using Nhibernate to save my data to my database. I want to make sure I close each Nhibernate session after each call.
I was using the following approach (using the castle facility) in my data access
using(var session = sessionManager.OpenSession())
using(var transaction = session.BeginTransaction())
{
// do work
transaction.Commit()
}
But when my main service method exits I am getting an error because I have already disposed of the Nhibernate session and I think the DTC needs this to do its commit.
My question is:
What would be the best way to close the Nhibernate session - after the DTC has committed (i.e after i have exited my service method?).
Thank you.