all groups > dotnet web services > november 2006 >
You're in the

dotnet web services

group:

webservice & nhibernate



webservice & nhibernate gaddoz
11/20/2006 10:35:32 PM
dotnet web services: Hi all,

I'm trying to set up a .NET webservice using in data access layer
Nhibernate (nhib 1.2.0 beta).
The first trouble I met was that a webservice cannot serialize
Interfaces, like IList<>.

After I workarounded it, now I get:

System.InvalidOperationException: There was an error generating the XML
document. ---> System.InvalidOperationException:
CProxyType<<My_NamespaceNAme>><<MyclassName>>_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2
cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported()


There is anyone out there using nhibernate for webservices??

Thanks.
Regards

gaddoz
Re: webservice & nhibernate Pablo Cibraro [MVP]
11/21/2006 10:14:56 AM
Hi,

Using the NHibernate entities as messages for a web service is not a good
approach. The client will only receive a xml copy of the entire entity
graph, which sometimes can involve many tables. (It is not going to receive
the entity itself).
In addition, you will have the serialization problems that you mention. It
is better to have a different class representing the web service message (A
simple class decorated with XML serialization attributes) and an adapter
layer that maps the message with the NHibernate entity.

Regards,
Pablo Cibraro.

[quoted text, click to view]

Re: webservice & nhibernate John Saunders
11/21/2006 2:53:14 PM
[quoted text, click to view]

I suggest that you add a third class of object - Data Transfer Objects
(DTO). You use a DTO to transfer data between the web

Re: webservice & nhibernate John Saunders
11/21/2006 2:57:00 PM
[quoted text, click to view]

Sorry, got sent too soon.

You use a DTO to transfer data between the web service and the client. It is
an object which represents the data in a simple format whose only purpose is
to transfer the data. There is no business logic and no database logic in
these objects, just data.

These will also map more closely to XML, and so will be more likely to be
compatible between client and server. For instance, instead of using
collections, the DTO will use arrays.

This allows you to use whatever business-layer or data layer object you like
inside of your server, yet to only present the data itself to the clients.

John

Re: webservice & nhibernate gaddoz
11/21/2006 8:32:58 PM
Thanks for the reply Pablo.

So, are you saying that in my pattern I should separate
"Model Objects" from "Nhibernate Objects"?

I don't like this idea!
Now I'm using model objects, a data access layer that uses these objects
against Nhibernate and a business layer that calls the DAL.

What do you suggest me?

Regards
Gaddoz



Pablo Cibraro [MVP] ha scritto:
[quoted text, click to view]
Re: webservice & nhibernate gaddoz
11/23/2006 12:10:30 AM
John Saunders ha scritto:
[quoted text, click to view]

Many thanks guys.

So, go on for DTO!

Any suggestion for a fast way for moving data between model and dto? :)

AddThis Social Bookmark Button