Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
来源:互联网 发布:乳胶枕头 知乎 编辑:程序博客网 时间:2024/06/02 11:48
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
- 软件架构师
- .NET 格式字符串速查
- Tip: execute ad-hoc JavaScript through eval function
- Tip - SQL报表打印的空白页问题
- Hot Tips: CSS 资源库 / CSS利器 - X光透视
- Web Service调用Nhibernate数据访问异常:xx cannot be serialized because it does not have a parameterless constructor
- Tip - SQL报表 - 按每N行记录将报表分页
- 《信息系统监理》之进度控制
- Tips - Web UI 资源索引
- DNN - skin quick reference
- Reporting Services Tip - 怎样隐藏Matrix中的列并且在Sub Total中显示该列的汇总
- Hot Tip - SQL 报表服务(Reporting Services) RDL
- IBuySpy - .NET open-source Portal 的起源
- Expression Web - .NET开发者的Web UI工具