![](/img/trans.png)
[英]Convert Java Arraylist return from Java WebService to C# 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.