当前位置: 动力学知识库 > 问答 > 编程问答 >

C# Web Service with a reference parameter

问题描述:

I must create a C# web service. I have a question. Is possible to use a ref parameter?

For example, I have this method

//my web service will fill the parameter by reference

int myWSMethod(int parameterA, ref string parameterB);

Is this possible with a web service?

网友答案:

If your problem is just trying to figure out how to return multiple values from a web service, just return a complex type instead.

[DataContract]
[Serializable]
public class myWSMethodResponse
{
    [DataMember]
    public int ErrorCode { get; set; }
    [DataMember]
    public string Report { get; set; }
}

public myWSMethodResponse myWSMethod(int parameterA)
{
  //code here
}
网友答案:

I'm not sure why you want to do it, but based on MSDN, you can do that.

Out and Ref Parameters.

In most cases, you can use in parameters (ByVal in Visual Basic) and out and ref parameters (ByRef in Visual Basic). Because both out and ref parameters indicate that data is returned from an operation, an operation signature such as the following specifies that a request/reply operation is required even though the operation signature returns void.

Example:

[ServiceContractAttribute]
public interface IMyContract
{
  [OperationContractAttribute]
  public void PopulateData(ref CustomDataType data);
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: