Reputation: 66727
Is it possible for a WCF Service method to return different types?
I already tried with Object but since it's not a DataContract type it doesn't work properly.
How can I do it?
Upvotes: 4
Views: 1523
Reputation: 1039408
You could use known types
. Those could also be defined in the config file using the <system.runtime.serialization>
section (see Additional Ways to Add Known Types in the article).
This being said you probably want to define a base data contract type that all other possible data contracts will derive from and have your operation return this base data contract instead of using object.
Upvotes: 6