[英]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可以做到。
Out
和Ref
参数 。在大多数情况下,可以使用in参数(在Visual Basic中为
ByVal
)以及out
和ref
参数(在Visual Basic中为ByRef
)。 因为out
和ref
参数都指示从操作返回了数据,所以如下所示的操作签名指定了即使操作签名返回void
也需要进行请求/答复操作。例:
[ServiceContractAttribute] public interface IMyContract { [OperationContractAttribute] public void PopulateData(ref CustomDataType data); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.