Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
2008-03-11 10:39
585 查看
web servcie调用nHibernate的数据访问代码读取数据库并生成一个实体实例时,得到了如下异常信息:
An exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll but was not handled in user code
Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: CProxyTypeTheGuide_BusinessAddressBusiness_NHibernate_ProxyINHibernateProxy1 cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported()
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Address(String n, String ns, Address o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_Account(String n, String ns, Account o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write10_GetByIDResponse(Object[] p)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer9.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- End of inner exception stack trace ---
似乎nHibernate的内部实现没有很好的支持xml serialization. 这篇blog中提高了一个方法可以解决此问题:将有关的实体类的lazy load 关掉。是的,这要牺牲性能。
http://rebelheart.squarespace.com/blog/web-services-and-nhibernate.html (需要代理才能打开此链接)
An exception of type 'System.Web.Services.Protocols.SoapException' occurred in System.Web.Services.dll but was not handled in user code
Additional information: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: CProxyTypeTheGuide_BusinessAddressBusiness_NHibernate_ProxyINHibernateProxy1 cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported()
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_Address(String n, String ns, Address o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_Account(String n, String ns, Account o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write10_GetByIDResponse(Object[] p)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer9.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- End of inner exception stack trace ---
似乎nHibernate的内部实现没有很好的支持xml serialization. 这篇blog中提高了一个方法可以解决此问题:将有关的实体类的lazy load 关掉。是的,这要牺牲性能。
http://rebelheart.squarespace.com/blog/web-services-and-nhibernate.html (需要代理才能打开此链接)
相关文章推荐
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- c# 调用Web Service的问题:The operation 'XXX' could not be loaded because it has a parameter...
- The disk cannot be added to Cluster Shared Volumes because it does not have any suitable partitions
- 关于applicationContext.xml cannot be opened because it does not exist的解决
- Hibernate mapping resource cannot be opened because it does not exist in a Spring + Hibernate Maven
- IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
- class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
- class path resource [applicationContext.xml] cannot be opened because it does not exist
- 关于applicationContext.xml cannot be opened because it does not exist的解决
- The service cannot be activated because it does not support ASP.NET compatibility
- java.io.FileNotFoundException: class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not
- 报错:classpath resource [com/qinkangdeid/mapping/] cannot be resolved to URL because it does not exist
- IDEA中Spring配置错误:class path resource [.xml] cannot be opened because it does not exist
- cannot be resolved to absolute file path because it does not reside in the file system
- java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist
- The service cannot be activated because it does not support ASP.NET compatibility
- class path resource [spring-mvc.xml] cannot be opened because it does not exist