my guess is, serializer while serializing your class triggers lazy 
loading and since the sessions was already closed at that time, hence 
the error.
Load Packages eagerly if you absolutely have to return your entities.
Better solution would be not to return entitles from services but to 
create DTOs.

adrian wrote:
> Hi!
>
> I have problem with returning active-record object with lazy loading
> from webservice method. Here is the code:
>
>                 [WebMethod]
>               [SoapDocumentMethod(ParameterStyle=SoapParameterStyle.Bare)]
>               public XmlDocument GetAnswer(int offer_id)
>               {
>                       using(new SessionScope())
>                       {                                                       
>                 {
>                               Offer offer = Offer.Find(offer_id);
>                               return offer;
>                       }
>                 }
>
> When I'm calling the method i'm getting an error:
>
> System.Reflection.TargetInvocationException: Exception has been thrown
> by the target of an
>       invocation. ---> NHibernate.LazyInitializationException:
>       Initializing[CairoParts.DB.Offer#427]-failed to lazily
> initialize a collection of role:
>       CairoParts.DB.Offer.Packages, no session or session was closed
>   at
> NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationException
> (
>        System.String message) [0x00000]
>   at
>  
> NHibernate.Collection.AbstractPersistentCollection.ThrowLazyInitializationExceptionIfNotConnected
>         () [0x00000]
>   at NHibernate.Collection.AbstractPersistentCollection.Initialize
> (Boolean writing) [0x00000]
>   at NHibernate.Collection.AbstractPersistentCollection.Read ()
> [0x00000]
>   at
>
> And even most interested thing is that this code works:
>
>                                         XmlSerializer s = new
> XmlSerializer(typeof(Offer));
>                                       StringWriter sw = new StringWriter();
>                                       s.Serialize(sw, offer);
>                                       XmlDocument xdoc = new XmlDocument();
>                                       xdoc.LoadXml(sw.ToString());
>
> and I'm out of ideas.
> Thanks for any help :)
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Castle Project Users" 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/castle-project-users?hl=.
>
>
>   

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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/castle-project-users?hl=.


Reply via email to