470,815 Members | 1,204 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

webservice & nhibernate

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>>_NHib ernate_ProxyINHibernateProxy_System_Runtime_Serial izationISerializable2
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

Nov 20 '06 #1
5 9363
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.

"gaddoz" <ga************@ANTISPAMgmail.comwrote in message
news:45***********************@reader4.news.tin.it ...
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>>_NHib ernate_ProxyINHibernateProxy_System_Runtime_Serial izationISerializable2
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

Nov 21 '06 #2
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:
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.

"gaddoz" <ga************@ANTISPAMgmail.comwrote in message
news:45***********************@reader4.news.tin.it ...
>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>>_NHi bernate_ProxyINHibernateProxy_System_Runtime_Seria lizationISerializable2
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

Nov 21 '06 #3
"gaddoz" <ga************@ANTISPAMgmail.comwrote in message
news:45**********************@reader2.news.tin.it. ..
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?
I suggest that you add a third class of object - Data Transfer Objects
(DTO). You use a DTO to transfer data between the web
Nov 21 '06 #4
"John Saunders" <john.saunders at trizetto.comwrote in message
news:eq**************@TK2MSFTNGP02.phx.gbl...
"gaddoz" <ga************@ANTISPAMgmail.comwrote in message
news:45**********************@reader2.news.tin.it. ..
>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?

I suggest that you add a third class of object - Data Transfer Objects
(DTO). You use a DTO to transfer data between the web
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
Nov 21 '06 #5
John Saunders ha scritto:
"John Saunders" <john.saunders at trizetto.comwrote in message
news:eq**************@TK2MSFTNGP02.phx.gbl...
>"gaddoz" <ga************@ANTISPAMgmail.comwrote in message
news:45**********************@reader2.news.tin.it ...
>>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?
I suggest that you add a third class of object - Data Transfer Objects
(DTO). You use a DTO to transfer data between the web

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

Many thanks guys.

So, go on for DTO!

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

Gaddoz
Nov 22 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Peter Kirk | last post: by
reply views Thread by Aquila Deus | last post: by
1 post views Thread by erin.sebastian | last post: by
reply views Thread by beantaxi | last post: by
4 posts views Thread by IceMan | last post: by
14 posts views Thread by thj | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.