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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Passing Proxies via Web Service
PostPosted: Thu Jun 02, 2005 11:38 pm 
Newbie

Joined: Thu Jun 02, 2005 10:58 pm
Posts: 5
Hi All,

I am working on a Prototype that is using a Persistence Manager that sits behind a web service. Domain objects are passed into and returned from the persistence manager which uses NHibernate.

Everything has been working well however when I introduced Lazy Loading of an associated class, I have some problems serializing the generated proxy object that represents the associated object.

On the server, I can see there are no problems with the Proxy object itself and NHibernatte is working as expected. e.g. when I access the properties while the session is open, it loads them and they are available when I close the session.

When the Persistence manager goes to return the generated Proxy Object, I get the following error:

"There was an error generating the XML document. --> CProxyTypeAddress_ISerializable_INHibernateProxy2 cannot be serialized because it does not have a default public constructor."

I was wondering how other people have got around this problem?

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 03, 2005 3:51 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Try posting this to the Castle project mailing list, people there are very responsive and will probably find a solution quickly.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 9:25 am 
Newbie

Joined: Wed Jun 22, 2005 9:20 am
Posts: 4
Sergey, you can ping me when some castle related question arises :-)

Gaj, the problem is that web services uses Xml Serializer, and this damn thing do not respect the serialization/deserialization protocol - which is used by dyn proxy. The proxies can't have default parameterless constructors (how would you pass the interceptor?).

We can try to work on this somehow, but I doubt it would be an easy fix.

_________________
Cheers,
hammett
http://www.castleproject.org/~hammett


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 5:56 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
I'm running into the same problem. Any word on a fix for this? That is other than disabling the proxy. So, there's no way to make it so that the proxy class has a public no arg constructor?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 6:08 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Can't the proxy class, just have a no arg constructor that calls the base class's no arg constructor?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 3:22 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I'd be interested in a better solution for this too.

I ended up generating my own webservice proxy classes based on my domain objects with the addition of an IsLazy property. All my domain object values are transferred to these webservice proxies if the object is loaded - if it's lazy then the proxy is left empty and it's IsLazy property is set to true.

I found I needed to do this anyway as any read only properties on any of my domain objects wouldn't be serialized anyway - another limitation of web services.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 8:35 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I am using indigo for my transport and I have my bindings set to webservices, so it's all xml over the line.

I'm doing a similar thing to symon. I do not serialize my associations that could be lazy. in the [onserializing] method hook that is called when serializing occurs, I check to see if my collection is loaded, or is lazy. If it's lazy, then I will not serialize.

Difference with symon is, that I can still use my domainobjects as dto's, instead of having to add a layer of generated proxies.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 3:35 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
This isn't really an NHibernate issue, but, another issue that I just ran into is that ASP.NET Web Services can't seem to serialize System.Collections.Generic.IList. It works with System.Collections.IList. i.e. it works with the non-generic list interface, but, not the generic one.

I was excited that I got generic collections working with the SVN version of NHibernate and then I ran into this problem and decided to switch back to use the non-generic collection classes for the time being.

I wonder if this works with WCF?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 7:07 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
yes, it works


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 12:31 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Shark,

Thanks for the info. Have you ran into problems with circular references and bidirectional relationships and ASP.NET Web Services? From what I understand you have to use RPC encoding rather than document encoding to get references to work. I've yet to get that working though (I tried setting [SoapRcpMethod]). Also, from what I've read, RPC encoding is basically frowned upon because it introduces potential interoperability issues. So far, my solution is to use a [XmlIgnore] attribute on one side of the relationship.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:01 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I'm using RPC encoding for exactly that reason and it seems to work over here. We're consuming with .NET and PHP and Delphi 7 with no trouble yet (well, some trouble with Delphi, but only when we introduced an object property whose type was System.Object which turns into and xml anyType mapping).

I think most web services historically have used RPC Encoded and it was Microsoft who chose to go with the Document Literal as their default.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 1:59 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Thanks for the info Symon. That's great to hear. So, are you just using standard ASP.NET Web Services, or, are you using WCF or WSE?

Is there much to switching from document to RPC encoding? As I mentioned, I've yet to get that to work. Basically, what I've done so far is add a,

Code:
[SoapRpcService]

at the top of my Web service class and comment out,

Code:
//[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]


When I view the WSDL file, I can see that it looks like it is using RPC. i.e. I can see stuff like the following.

Code:
- <wsdl:binding name="WebServiceSoap" type="tns:WebServiceSoap">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
- <wsdl:operation name="Ping">
  <soap:operation soapAction="http://at.uchicago.edu/Reservations/Ping" style="rpc" />
- <wsdl:input>
  <soap:body use="encoded" namespace="http://mynamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </wsdl:input>
- <wsdl:output>
  <soap:body use="encoded" namespace="http://mynamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
  </wsdl:output>
  </wsdl:operation>


But, if I try to execute a method that returns an object that has a circular reference I still get the following exception which is the same thing that I get using document encoding.

Code:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: A circular reference was detected while serializing an object of type Reservations.Persistence.Entity.Reservation.


I'm pretty new to Web services. I'm guessing I'm just doing something stupid. Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 7:06 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
i'm not using asp.net webservices, but indigo (wcf).

There is the possibility to serialize circular references which can be switched on. Then everything works fine, using either xml or tcp.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 11:31 am 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
That's great to hear. Improved serialization so as to not run into these kinds or problems is exactly what I'm hoping for in WCF. Thanks for the info.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 2:52 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Actually, I'm using ASP.NET 2.0 with the same settings and attributes as you are:

Code:
[WebService()]
   [SoapRpcService()]


on the class, and

Code:
[WebMethod()]


on the methods. The class derives from System.Web.Services.WebService and everything works as expected.

I had the circular reference problem when I was using DocumentLiteral (the default setting) but as soon as I changed to SoapRpcService everything works fine. And I certainly have plenty of circular references in my domain model!

Sorry not to be of more help...

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.