繁体   English   中英

具有参考参数的C#Web服务

[英]C# Web Service with a reference parameter

我必须创建一个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
}

我不确定为什么要这样做,但是基于MSDN可以做到。

OutRef参数

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

例:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM