Confused over webservices

Posts   
 
    
Posts: 19
Joined: 08-Jan-2007
# Posted on: 21-Mar-2007 11:26:29   

Hi

I'm a bit confused on how I should be passing entities/entitycollections between tiers using webservices. All tiers are .Net so I just want to be able to use entities and entity collections in both the business tier AND the presentation tier.

For example, if I return an entity collection from a webmethod, it arrives at the client as a dataset. I believe this is something to do with the IXmlSerializable interface, although I don't really understand this.

How can I convert this dataset back into the correct entitycollection object? If this is not possible, how else can I pass entities/entitycollections through webservices? I keep seeing mention of DTOs but can someone explain or give an example?

Many thanks

Andrew

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Mar-2007 08:42:55   

What's the .NET Framework version that you are using? 1.1 or 2? Have you checked the manual for the section "Using the generated code -> XML Webservices support?"

P.S. If both the client and the server are .NET clients, then you can use .NET Remoting.

Posts: 19
Joined: 08-Jan-2007
# Posted on: 22-Mar-2007 10:15:02   

Hi, I'm using .Net 2.0.

I have checked that section of the manual but don't like the idea of creating the schemaimporter project - it seems very long-winded. We write a lot of web applications and don't want to have to go through that for each one. Unfortunately remoting isn't an option either due to our infrastructure.

Don't worry though. I've since read the "XML Support" section of the manual and discovered the ReadXml/WriteXml methods, so we can serialize objects prior to sending to/from a webmethod, then deserialize at the other end. It just means our webmethod parameters and return values will be strings rather than entities & entitycollections, so the webmethod signature isn't intuitive when you look at it.

Can you confirm that the ReadXml/WriteXml methods will serialize/deserialize an entire hierarchy of objects? E.g. if I have a customer entity, with an order entitycollection, each of these with an order item entitycollection, etc, etc. If I serialize then deserialize the customer, will it reinstantiate the entire object graph?

I'm still interested to know about DTOs and how these can be used to pass entities/entity collections to/from webservices, with any examples.

Thanks again

Andy

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 22-Mar-2007 15:32:58   

Can you confirm that the ReadXml/WriteXml methods will serialize/deserialize an entire hierarchy of objects? E.g. if I have a customer entity, with an order entitycollection, each of these with an order item entitycollection, etc, etc. If I serialize then deserialize the customer, will it reinstantiate the entire object graph?

Sure, it's mentioned in the manual in the first paragraph of the XML Support section. It also says that the xml produced for an object graph can be huge, so you may want to use the compact version.