我必须创建一个C#Web服务。我有个问题。可以使用ref
参数吗?
例如,我有这个方法
//my web service will fill the parameter by reference
int myWSMethod(int parameterA, ref string parameterB);
这可以通过网络服务实现吗?
答案 0 :(得分:6)
如果您的问题只是想弄清楚如何从Web服务返回多个值,那么只需返回复杂类型。
[DataContract]
[Serializable]
public class myWSMethodResponse
{
[DataMember]
public int ErrorCode { get; set; }
[DataMember]
public string Report { get; set; }
}
public myWSMethodResponse myWSMethod(int parameterA)
{
//code here
}
答案 1 :(得分:1)
我不确定你为什么要这样做,但基于MSDN,你可以做到。
Out
和Ref
参数。在大多数情况下,您可以在参数(Visual Basic中为
ByVal
)和out
以及ref
中使用 参数(Visual Basic中的ByRef
)。因为out
和ref
参数都表示 该数据从操作返回,操作签名如下 指定即使操作签名返回void
,也需要请求/回复操作。示例:强>
[ServiceContractAttribute] public interface IMyContract { [OperationContractAttribute] public void PopulateData(ref CustomDataType data); }