-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: NHibernate and Web Serivces
PostPosted: Mon Feb 26, 2007 10:34 am 
Newbie

Joined: Tue May 30, 2006 11:54 am
Posts: 6
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 7:42 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 9:26 am
Posts: 27
Location: Barcelona
I'm having a similar problem, but with deserialization.

When I send my objects to the web service I get this error:

+ ex {"System.Web.Services.Protocols.SoapException: Server was unable to read request. ---> System.InvalidOperationException: There is an error in XML document (1, 294). ---> System.InvalidOperationException: Could not deserialize global::System.Collections.IList. Parameterless constructor is required for collections and enumerators.\n at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read3_User(Boolean isNullable, Boolean checkType)\n at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read9_Order(Boolean isNullable, Boolean checkType)\n at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.Read17_ImportOrders()\n at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer.Deserialize(XmlSerializationReader reader)\n at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)\n --- End of inner exception stack trace ---\n at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)\n at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle)\n at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()\n --- End of inner exception stack trace ---\n at System.Web.Services.Protocols.SoapServerProtocol.ReadParameters()\n at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()"} System.Exception {System.Web.Services.Protocols.SoapException}

What is strange is that the WSobjects do not have an IList (i looked in the reference.cs class). So which IList is it having problems with?


Top
 Profile  
 
 Post subject: Webservices xml exception
PostPosted: Tue Apr 24, 2007 4:24 pm 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
The problem could be a circular dependency. Parent -> Child -> Parent.

I usually do it this way:

[WebMethod]
public List<Story> GetStoriesBySubmittingUser( int userID )
{
return NHDaoFactory.GetStoryDao().GetByUser( userID ) as List<Story>;
}


Top
 Profile  
 
 Post subject: Webservices xml exception
PostPosted: Tue Apr 24, 2007 4:27 pm 
Beginner
Beginner

Joined: Fri Jul 14, 2006 1:51 pm
Posts: 27
The problem could be a circular dependency. Parent -> Child -> Parent.

I usually do it this way:
Code:
[WebMethod]
public List<Story> GetStoriesBySubmittingUser( int userID )
{
        return NHDaoFactory.GetStoryDao().GetByUser( userID ) as List<Story>;
}


And in the Story object:

Code:
[XmlIgnore]
public virtual IList< Comment > CommentList
{
       get { return commentList; }
       set { commentList = value; }
}


because the Story has a list of comments which have a Story, Parent -> Child -> Parent.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.