0

I have been trying to return an ArrayList from a WebService and I am confused about how to get it going as I get an error message saying

"Cannot implicitly convert type 'object[]' to 'System.Collections.ArrayList'".

Here is the Code for the Web Service names 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

}

The Code where I consume the Web Service:

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'          
    }

}

It would be great if you can help me handle this issue and access the data in the ArrayList returned by the Web Service.

Thanks in Advance!

2
  • I'd recommend using a generic List<T> over an ArrayList .... Commented Mar 1, 2017 at 21:23
  • I found a solution!! ....while consuming the Web Service, I can do this : ArrayList data = new ArrayList(client.PVTLog(serialNo, groupNo, strFilePath)); ..it works!! Commented Mar 1, 2017 at 23:19

2 Answers 2

1

on your service reference click configure: enter image description here

Select your expected collection type:

enter image description here

click OK, then update the service reference: enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks for the response. ..What if I have the Service Reference as a Web Reference ?
0

When calling the Web Service, all I had to do was declare the returned object from the Web Service as a new ArrayList.

In the above code that I have posted, I called the Web Service like this :

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'          
    }

}

But all I had to do was this :

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

i.e. Declare the returned object[] from the Web Service as a new ArrayList!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.