带有引用参数的C#Web服务

带有引用参数的C#Web服务,c#,web-services,visual-studio,pass-by-reference,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); 这在web服务中可能吗?如果您的问题只是试图找出如何从web服务返回多个值,那么只需返回复杂类型即可 [DataContract] [Serializable] public class my

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

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

这在web服务中可能吗?

如果您的问题只是试图找出如何从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
}

如果您的问题只是试图找出如何从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
}

我不知道你为什么要这么做,但基于这个,你可以这么做

输出
参考
参数

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

示例:

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

我不知道你为什么要这么做,但基于这个,你可以这么做

输出
参考
参数

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

示例:

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

你为什么不把信息作为常规参数传递呢?你能解释一下为什么你认为你需要一个ref参数吗?看看这个
,所以当你通过web服务交换一个变量时,它会被序列化。您希望
ref
做什么?请解释您试图解决的真正问题。@DJ KRAZE我想使用这种类型的参数,因为我希望有一个返回错误代码(return int)和报告(ref parameter)的方法web服务的应用esecution@GgSalent更好的方法是返回字符串值并在出错时抛出自定义异常,而不是使用
ref
parameter@DStanley不,请参阅谷歌、推特等API。包含
状态和实际数据的所有返回和对象。因此,
EkoostikMartin
的解决方案很好。为什么不把信息作为常规参数传递呢?你能解释一下为什么你认为需要一个ref参数吗?看看这个
So
posting当你通过web服务交换一个变量时,它会被序列化。您希望
ref
做什么?请解释您试图解决的真正问题。@DJ KRAZE我想使用这种类型的参数,因为我希望有一个返回错误代码(return int)和报告(ref parameter)的方法web服务的应用esecution@GgSalent更好的方法是返回字符串值并在出错时抛出自定义异常,而不是使用
ref
parameter@DStanley不,请参阅谷歌、推特等API。包含
状态和实际数据的所有返回和对象。因此,
EkoostikMartin
的解决方案很好。虽然不是OP要求的,但这绝对是最明智的解决方案。虽然不是OP要求的,但这绝对是最明智的解决方案。