views:

122

answers:

1

I'm kinda new to web services and want to make sure I am doing things correctly.

I have a custom object which has sub objects as well. (let's say Company object, sub object is collection of Employee objects)

I want the web service to return a collection of Company objects. Do I make the service return a Dataset and custom generate a dataset with datatables representing the different objects?

What is the best way to do this? I tried to just serialize it, but that doesn't seem to work either.

I tried this dll http://www.codeproject.com/KB/linq/linqsqlserialization.aspx

But the output XML doesn't seem to include the sub object.

+1  A: 

Whether you're using the 2.0 framework (with ASMX web services, which are no longer supported) or the 3.0 framework (with WCF), both will handle return of complex objects provided they are serializable. In the 2.0 framework, that means capable of marking your objects with the [Serializable] attribute. In the 3.0 framework, you're implementing serialization using the [DataContract] attribute. http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx and http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx.

Both frameworks will enable the client-side WSDL in preparation for clients to consume your complex objects. Since they're non-primitives, you'll be limited to SOAP-based clients because the return payload will require complex representation.

jro