jemiller wrote:
One problem that you may run into is that if you try to serialize a class that has lazy="true" and it was lazily initialized, XML serialization will fail. This is because Castle.DynamicProxy doesn't generate a no arg constructor for the proxy class it generates. XmlSerializer which is what ASP.NET web services uses for serialization requires this and as a result the serialization will fail.
I asked the developer of DynamicProxy if he could add a no arg constructor. However, as far as I can tell, he really doesn't give a damn and doesn't take the time to even bother responding. His claim seems to be that an iterceptor needs to be passed to the object. However, in the case of web services, you really only need the class to act as a data structure and don't need the proxy behavior anyways because the object has already been lazy initialized when it was serialized.
It's probably not a good idea to try to return these objects from a web service method anyway, but, it would be nice to be able to do it for simple cases.
It sounds like you aren't returning NHibernate returned objects from your web service methods, so, maybe you won't run into that problem.
That's not happening in my implementation, because from the beginning we did "wrap" the NH Entities into Domain Entities and mapped their properties to the NH Entities properties, so the serializations goes indirectly against the NH Entity, it serializes the Domain Entity.
Reduced sample:
Code:
public class NHEntity {
[...]
private int _PersonID;
private string _PersonName ;
[...]
public int PersonName {
get { return _PersonName }
set { _PersonName = value; }
}
[...]
}
[Serializable()]
public class DomainEntity: DomainEntityBase {
private NHEntity _Internal;
[...]
public string PersonName {
get { return _Internal.PersonName; }
set { _Internal.PersonName = value; }
}
}
That was the best approach we find to solve the Serialization problem, and also solved the IList serialization problem ;)