Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to return objects from a WebService?

Tags:

web-services

Instead of returning a common string, is there a way to return classic objects? If not: what are the best practices? Do you transpose your object to xml and rebuild the object on the other side? What are the other possibilities?

like image 453
Paul Avatar asked Aug 15 '08 01:08

Paul


3 Answers

As mentioned, you can do this in .net via serialization. By default all native types are serializable so this happens automagically for you.

However if you have complex types, you need to mark the object with the [Serializable] attribute. The same goes with complex types as properties.

So for example you need to have:

[Serializable]
public class MyClass
{
    public string MyString {get; set;}

    [Serializable]
    public MyOtherClass MyOtherClassProperty {get; set;}
}
like image 193
lomaxx Avatar answered Nov 14 '22 07:11

lomaxx


If the object can be serialised to XML and can be described in WSDL then yes it is possible to return objects from a webservice.

like image 27
Kev Avatar answered Nov 14 '22 06:11

Kev


Yes: in .NET they call this serialization, where objects are serialized into XML and then reconstructed by the consuming service back into its original object type or a surrogate with the same data structure.

like image 3
Jon Limjap Avatar answered Nov 14 '22 08:11

Jon Limjap