Reputation: 6838
I'm struggling with understanding how to define a WSDL that allows for returning a generic type Object that can be cast on the client to the real object. For example, I have a single return type Object for 4 different method calls. The 4 different methods have different parameter Objects when called. (e.g. CreatePerson(Person), CreateAnimal(Animal), etc...) Each one returns a ResultObject has a "Object" property that would contain the operated on object parameter. (e.g. CreatePerson(Person) would return ResultObject.Object = Person, the returned Person object would have updated properties, like ID, some timestamp, etc...)
Should I just have a Result object for each object? (e.g. ResultPerson = CreatePerson(), ResultAnimal = CreateAnimal(), etc...)
I have to layout the API before coding so thanks for any advice!
Upvotes: 1
Views: 1308
Reputation: 340708
Should I just have a
Result
object for each object? (e.g.ResultPerson = CreatePerson()
,ResultAnimal = CreateAnimal()
, etc...)
Absolutely! There is nothing more irritating than a strongly-typed language that must deal with an API returning a generic Object
. You get almost no benefit for the price of making your API really hard to use.
Don't be upset about the proliferation of classes. After all they are created by some tool like wsdl2
-something (e.g. wsdl2java
). If all your results have some common properties, consider having one abstract base type (e.g. Animal
) and extend. That will make your API even better.
Upvotes: 1