簡體   English   中英

如何從C#中的WebService返回ArrayList?

[英]How to return an ArrayList from a WebService in C#?

我一直在嘗試從Web服務返回ArrayList,但由於收到錯誤消息,我對如何使其運行感到困惑

“無法將類型'object []'隱式轉換為'System.Collections.ArrayList'”。

這是Web服務名稱DDRParserService.asmx的代碼。

public ArrayList PVTLog(string reqNo, string groupNo, string filePath)
{
ArrayList logData = new ArrayList();

//Calling the Parsing Logic file
logData = ParsePVTLog_Service(reqNo, groupNo, filePath); 

// I get the ArrayList in logData and return it
return logData

}

我使用Web服務的代碼:

private void btnParse_Click(object sender, EventArgs e)
{
  string strFilePath = txtOpenFile.Text;
  string serialNo = txtSerialNumber.Text;
  string groupNo = txtGroupNumber.Text;
  ArrayList data = new ArrayList();

  if (txtOpenFile.Text != "")
    {
      DDRParsingService.DDRParserService client = new DDRParsingService.DDRParserService();

      // Call the Web Service
     data =  client.PVTLog(serialNo, groupNo, strFilePath);
      // I get the error : Cannot implicitly convert type 'object[]' to 'System.Collections.ArrayList'          
    }

}

如果您可以幫助我解決此問題並訪問Web服務返回的ArrayList中的數據,那就太好了。

提前致謝!

在服務參考上,單擊配置: 在此處輸入圖片說明

選擇您期望的收集類型:

在此處輸入圖片說明

單擊確定,然后更新服務參考: 在此處輸入圖片說明

調用Web服務時,我要做的就是將Web服務中返回的對象聲明為新的ArrayList。

在上面發布的代碼中,我這樣調用Web服務:

private void btnParse_Click(object sender, EventArgs e)
{
  string strFilePath = txtOpenFile.Text;
  string serialNo = txtSerialNumber.Text;
  string groupNo = txtGroupNumber.Text;
  ArrayList data = new ArrayList();

  if (txtOpenFile.Text != "")
    {
      DDRParsingService.DDRParserService client = new DDRParsingService.DDRParserService();

      // Call the Web Service
     data =  client.PVTLog(serialNo, groupNo, strFilePath);
      // I get the error : Cannot implicitly convert type 'object[]' to 'System.Collections.ArrayList'          
    }

}

但是我要做的就是:

data = new ArrayList(client.PVTLog(serialNo, groupNo, strFilePath));

即從Web服務聲明返回的object []作為新的ArrayList!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM