NHibernate session management in WCF application - wcf

I am building a WCF application, using NHibernate for the persistence layer. A lot of documentation thats out there is about using NHibernate with ASP.NET applications. But very little on the best ways to manage NHibernate Sessions in a WCF application.
After reading up on Instance Management Techniques in WCF applications, I am going to use "per-call Services". Drawing parallel with ASP.NET, this is like opening NHibernate sessions on Application_BeginRequest and closing them on Application_EndRequest. Billy McCafferty's S#arp Architecture has a great example of doing this very elegantly. But I am finding it a little hard to use a similar concept in a WCF application.
Any code samples or pointers to blogs with examples, will be greatly appreciated.

http://www.igloocoder.com/archive/2009/04/23/wcf-and-nhibernate-redux.aspx -> https://igloocoder.net:8443/svn/IglooCommons/trunk/src/IglooCoder.Commons/WcfNhibernate/

I found another good example -
http://realfiction.net/go/133

Related

What is the best practice using NHibernate 3.0 with WCF Web Services?

There seems to be quite a bit of information regarding using NHibernate and WCF Web Services but I'm struggling to find a definitive guide on how to implement the two technologies together in a efficient, thread safe way.
Specifically I want to grab the ISession object and uses that to get and save data through my existing repositories. My Business Objects, Unit Tests and ASP.NET Web Application all use the NHibernate framework and it works just great (it's my first hobby project using an ORM). My big question is how to combine this great framework with WCF Web Services.
I've read that version 3.0 NHibernate has NHibernate.Context.WcfOperationSessionContext but I'm unsure of it's implementation (see this question). From what I understand, one option is to store the ISession object in the OperationContext?
Can anyone point me in the direction of a implementation example?
Many thanks.
Here is a post describing, in detail, all the steps for registering and using the WcfOperationSessionContext. It also includes instructions for using it with the agatha-rrsl project.
WCF and Nhibernate work together in Sharp Architecture project. You can have a look at their implementation

Spring.NET, NHibernate and WCF: Session Management

I know that this issue has been discussed but all answers seem to be quite outdated (back in 2008).
I have a perfectly well configured application architecture with Spring.NET DI and transaction management and NHibernate. Session management works well within my integration tests.
But: what is the best way to handle the NHibernate session within WCF?
Are there any new concepts, frameworks?
Best
Max
I have implemented session/transaction management in WCF with the help of IDispatchMessageInspector. It allows you to react on events like Begin/End reqest.
I have wrote a blog post about it. Its in russian, but code is in c# :). I hope it will help you.
Also you can have a look at sharp architecture. They implemented session/transaction management for both mvc and wcf.

Are NHibernate and XML Webservices (.asmx) a good match?

I'm looking at new architecture for my site and was wondering if pairing NHibernate with a web service core is a good idea. What I want to do is make my webservice the core of my business, from the site front ends to the utilties I write. I'm trying to make all of my UIs completely ignorant of anything but my service API's.
In a simple strawman experiement, I'm running into issues with Serialzing my Iesi ISets....this is causing me to rethink the strategy altogether.
I know I could just develop a core Library (dll) and reference that in each of my applications, but maintaining that dll's version over a minimum of 6 applications seems like it's going to cause me much pain.
With NHibernate, what are the pro's and con's of those two approaches?
I see no problem in using NHibernate and webservices together - I just don't think it's a good idea to send the entities themselves over "to the other side".
A better approach is to use a set of DTOs that are made for the service - then you won't be running into issues like that of serializing unknown types and such.
You can use a library like AutoMapper to do the mapping from the entities to the DTOs.
There's a lot of stuff written about this, some of it:
http://martinfowler.com/bliki/FirstLaw.html
http://ayende.com/Blog/archive/2009/05/14/the-stripper-pattern.aspx
http://elegantcode.com/2008/04/27/dtos-or-serialized-domain-entities/
DTOs vs Serializing Persisted Entities
As a side note for the service it self, you could design wise use an approach like Davy Brion describes here: http://davybrion.com/blog/2009/11/requestresponse-service-layer-series/
I don't know NHibernate, but want to remind you that you should be using WCF for new web service development, unless you are stuck in the past (.NET 2.0). Microsoft now considers ASMX web services to be "legacy technology", and you can imagine what that means.

Ways to design heavy data-centric web application in Silverlight

I have to build a web application in Silverlight. This application is entirely data centric with SQLServer 2008 as the database.
What are different ways of handling this design problem? Someone told me RIAServices would be a great option, but I am not completely knowledgable of it.
One simple option I know of is creating WCFService and exposing the methods to perform the actions on the database object.
Any suggestions?
You answered your own question :).
3rd option ADO.NET dataservice. But RIAService is the #1 right now for n-tier LOB applications.

Models for developing WCF applications

Do you know any blueprints for organizing a WCF application in a way similar to Service Factory?
The problem is that although Service Factory is well organized, my application is a medium-sized one and it would be an overkill to use the factory - some of the sub-projects that the factory creates for me, I wouldn't ever use.
So what are the common models/architectures/blueprints/patterns for organizing the structure of a WCF application for a mid-sized project?
Thank you.
This article is great in terms of how to set up your project structure the right way:
http://code-magazine.com/Article.aspx?quickid=0809101