带参考参数的C#Web服务

时间:2013-04-04 18:58:27

标签: c# web-services visual-studio pass-by-reference

我必须创建一个C#Web服务。我有个问题。可以使用ref参数吗? 例如,我有这个方法

//my web service will fill the parameter by reference
int myWSMethod(int parameterA, ref string parameterB);

这可以通过网络服务实现吗?

2 个答案:

答案 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,你可以做到。

  

OutRef参数

     

在大多数情况下,您可以在参数(Visual Basic中为ByVal)和out以及ref中使用       参数(Visual Basic中的ByRef)。因为outref参数都表示       该数据从操作返回,操作签名如下       指定即使操作签名返回void,也需要请求/回复操作。

     

示例:

[ServiceContractAttribute]
public interface IMyContract
{
  [OperationContractAttribute]
  public void PopulateData(ref CustomDataType data);
}