What is the best way to return multiple values from a WCF service?
+3
A:
First of all, this must be a duplicate.
Just create a class with properties for the values. Make the class a [DataContract] and the properties [DataMember]. Return an isntance of that class. Works on all clients.
John Saunders
2009-05-15 18:57:12
+1
A:
In a separate object, e.g.:
public class DTO
{
public string Data1 { get; set;}
public string Data2 { get; set;}
}
and you then return an instance of DTO from the method.
Frans Bouma
2009-05-15 18:57:19
Yeah, but then you need to decorate this with [DataContract], I'd say...
marc_s
2009-05-15 20:00:11
You don't have to. You can also create a service contract and define it as a known type on that service, place the DTO classes in a separate assembly and reference it both in client and service
Frans Bouma
2009-05-16 08:23:55
A:
Either wrap them in a separate class that will be decorated with [DataContract] and return it from your method or use out parameters in your method call.
bychkov
2009-05-15 22:48:57