Hello, I have one problem with NHibernate and Web-services.
I have the following method in my Web Service that works:
Code:
[WebMethod()]
public MyEntity [] LoadAllPlans ()
{
IList<MyEntity> entitiesList = Session.CreateCriteria(typeof(MyEntity)).List<MyEntity>();
KpmPlanEntity [] entities = new KpmPlanEntity[entitiesList.Count];
entitiesList.CopyTo(entities, 0);
return entities;
}
It works fine!
And I have another method:
Code:
[WebMethod()]
public MyEntity LoadPlan(Guid id)
{
return Session.Load(typeof(MyEntity), id) as MyEntity;
}
And it fails! With exception:
SoapException:
Code:
System.Web.Services.Protocols.SoapException was unhandled
Message="System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: CProxyTypeKpmPlanEntityEntities_INHibernateProxy_ISerializable2 cannot be serialized because it does not have a parameterless constructor.\n at System.Xml.Serialization.TypeDesc.CheckSupported()\n at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)\n at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)\n at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Object o)\n at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write10_KpmPlanEntity(String n, String ns, KpmPlanEntity o, Boolean isNullable, Boolean needType)\n at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write13_LoadPlanResponse(Object[] p)\n at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer5.Serialize(Object objectToSerialize, XmlSerializationWriter writer)\n at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)\n --- End of inner exception stack trace ---\n at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)\n at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)\n at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)\n at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)\n at System.Web.Services.Protocols.WebServiceHandler.Invoke()\n --- End of inner exception stack trace ---"
Source="System.Web.Services"
Actor=""
Lang=""
Node=""
Role=""
But If I use Createria instead of simple load then it works!
What is the problem? Where I did a mistake?
NHibernate version: 1.2.0 Beta3
Name and version of the database you are using: MS SQL Server 2000