Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
来源:互联网 发布:太原seo招聘 编辑:程序博客网 时间:2024/05/22 18:23
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
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- Database diagram support objects cannot be installed because this database does not have a valid owner.
- Database diagram support objects cannot be installed because this database does not have a valid own
- WCF The service cannot be activated because it does not support ASP.NET compatibility
- The service cannot be activated because it does not support ASP.NET compatibility
- Hibernate mapping resource cannot be opened because it does not exist in a Spring + Hibernate Maven
- applicationContext.xml cannot be opened because it does not exist
- cannot be opened because it does not exist
- c# 调用Web Service的问题:The operation 'XXX' could not be loaded because it has a parameter...
- 关于class path resource [WEB-INF/content/] cannot be resolved to URL because it does not exist解决办法
- SQL 2005 建立数据库图表时出现以下错误Database diagram support objects cannot be installed because this database does not have a valid owner 解决
- webservice [META-INF/xfire/services.xml] cannot be opened because it does not exist
- 关于applicationContext.xml cannot be opened because it does not exist的解决
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- CSS:css减肥瘦身工具
- 中国的IT企业和客户,哪个更贱?
- 有关《大道至简》的几点讨论~
- 测试-答对5道题的人是天才,答对4道的是帅才,答对3道的是将才,答对2道的是奇才,答对1道的是人才
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- UBB解析优化的心得:Regex构造函数的性能
- Tip - SQL报表 - 按每N行记录将报表分页
- 《软件测试管理》第14章软件测试常见问题——(四)测试技术常见问题
- 命名空间大小写导致的not CLS-compliant
- CSS:CSS Hack 汇总快查
- Tips - Web UI 资源索引
- 《Web全面性能测试实战》第2章Web全面性能测试模型
- Orcas Team Suite 2007年6月份CTP的下载链接