nHibernate and webservices

191 views
Skip to first unread message

Jakes

unread,
Aug 27, 2012, 3:01:57 AM8/27/12
to nhu...@googlegroups.com
I have a problem using nHibernate in my webservice.

Its first time i have used nHibernate in a Webservice but have used it in my ASP.NET applications for the last 4-5 years.

What i would like to do is have some of the functions in my ASP.NET application be available though a webservice.
I have made som DataTransferObjects because i dont need all the data for the objects going though the webservice.

When i try to get some data though the DAL (which works fine in the ASP.NET application) then i get an error that the session (gues its the nHibernate session) is not initialized???

Do i have to do something speciel with the nHibernate session to get it to work though a webservice that i do not need in a ASP.NET aplication.

Hobe some one can help me.

Regards,
Jacob

Ricardo Peres

unread,
Aug 28, 2012, 7:51:49 AM8/28/12
to nhu...@googlegroups.com
You are using lazy collections/properties, right? How are you passing data from your entities to the DTOs?
Can you post your code?

Jakes

unread,
Sep 4, 2012, 3:24:45 PM9/4/12
to nhu...@googlegroups.com
Hi,

I think my problem is im using the same instance all the time in my webapplications.

Like this is my businessObject which initialize the nHibernate session in its constructor.

        public static Business Get()
        {
            return _instance ?? (_instance = new Business());
        }

So when i need to use my business i do it like this.
            IBusiness biz = Business.Get();

            biz.Category.Read();

Can i do this in a webservice.

Regarding how im passing the data to the DTO im using linq like this, where WsEvent is my DTO and Event is my nhibernate object.:
        public WsEvent[] GetServiceEvents()
        {
            return (from e in Business.Get().Event.Read() select new WsEvent {EventId = e.Id, EventName = e.Name})
                    .ToArray();
        }

Any suggestions what to do?

Regards,
Jacob

Oskar Berggren

unread,
Sep 5, 2012, 4:05:45 AM9/5/12
to nhu...@googlegroups.com
I don't quite understand how your code works, but some general pointers:
The session is commonly rather short-lived (but not too short. "unit-of-work" is common while "application-lifetime" is not typical).
If the session is in what appears to be a singleton Business object, how are you handling multithreading?

/Oskar


2012/9/4 Jakes <ImJ...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/ELLcxMq6aq4J.

To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Reply all
Reply to author
Forward
0 new messages