views:

250

answers:

3

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
+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
Yeah, but then you need to decorate this with [DataContract], I'd say...
marc_s
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
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