What is the best way to return multiple values from a WCF service?
从WCF服务返回多个值的最佳方法是什么?
3 个解决方案
#1
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.
只需创建一个包含值属性的类。使类成为[DataContract]和属性[DataMember]。返回该类的意义。适用于所有客户。
#2
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.
然后从方法返回DTO的实例。
#3
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.
将它们包装在一个单独的类中,该类将使用[DataContract]进行修饰,并从方法中返回它或在方法调用中使用out参数。
#1
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.
只需创建一个包含值属性的类。使类成为[DataContract]和属性[DataMember]。返回该类的意义。适用于所有客户。
#2
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.
然后从方法返回DTO的实例。
#3
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.
将它们包装在一个单独的类中,该类将使用[DataContract]进行修饰,并从方法中返回它或在方法调用中使用out参数。