Hi all,
now i programm a 3tier project and i use nhibernate to persist data object.
but i get a problem while calling the web servies methode. the exception message looks like this:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: CProxyTypeHM_ClassLibraryRoomHM_ClassLibrary_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.Write4_Room(String n, String ns, Room o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write18_Room(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.RoomSerializer.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(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
i don't understand the message "cannot be serialized because it does not have a parameterless constructor.
", cause i've already a constructor in my class 'Room'.
using System;
using System.Collections.Generic;
using System.Text;
namespace HM_ClassLibrary
{
[Serializable]
public class Room
{
private int _id;
public virtual int Id
{
get
{
return _id;
}
set
{
_id = value;
}
}
private string _number;
public virtual string Number
{
get
{
return _number;
}
set
{
_number = value;
}
}
private int _hotelId;
public virtual int HotelId
{
get { return _hotelId; }
set { _hotelId = value; }
}
private int _typeId;
public virtual int TypeId
{
get { return _typeId; }
set { _typeId = value; }
}
public Room()
{ }
...
}
}
and there are the mapping code
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="HM_ClassLibrary.Room, HM_ClassLibrary" table="Room">
<id name="Id" column="RoomId" type ="System.Int32" >
<generator class="native" />
</id>
<property name="Number" column="RoomNumber" length="3" not-null="true"/>
<many-to-one name="TypeId" column="RoomTypeId" not-null="true" lazy="false"
cascade="all"
unique ="true"
class ="HM_ClassLibrary.RoomType, HM_ClassLibrary"/>
<many-to-one name="HotelId" column= "RoomHotelId" not-null="true" lazy="false"
cascade ="all"
unique ="true"
class ="HM_ClassLibrary.Hotel, HM_ClassLibrary"/>
</class>
</hibernate-mapping>
has anyone any experiences how to resolve those problems.
thx
|