Search code examples
wcfpass-by-referenceref

How can I use ref in WCF?


Can't I use ref in WCF to return data ?

This is my WCF file.

public myDataset SearchInfo(string accountName, string accountId, ref int totalRecords)

Although totalRecords is a non-zero number, I always get 0. I have to get both myDataset and totalRecords. How should I try? I am new to WCF.

Thanks in advance.

UPDATE :

It works well. My bad !!!


Solution

  • If you're trying to return multiple values, it's probably better to add a data contract with a data member for each value (dataset and total records in your case).

    [DataContract]
    public class SearchInfoResult
    {
      [DataMember]
      public myDataSet DataSet {get; set;}
    
      [DataMember]
      public int TotalRecords {get; set;}
    }