views:

125

answers:

2

I've got the unenviable task of cleaning up a rather messy VB.Net client. The general plan is to move all calculations to WebServices, and I can see exactly how to do this, but it involves passing a large number of different variables to the WebServices.

I chose to use an ArrayList as I've worked with them heavily in Java, and have had no issues passing ArrayLists between the C# (ASMX) WebService and a C# client (Windows Forms-based).

However, the VB.Net client app doesn't want to pass the ArrayList into the WebServices, giving a compiler error "Value of type 'System.Collections.ArrayList' cannot be converted to '1-dimensional array of Object'."

+2  A: 

Just call ToArray() on your ArrayList when you pass it to the web service.

ck
Thanks for the reply, but still no joy. Same error on this line:Dim results As ArrayList = webQuote.makeQuoteFromQuoteInputs(quoteValues.ToArray()) Where quoteValues is the filled ArrayList
Gargravarr
Okay, to clarify this did solve the problem when passing the list TO the WebService, but I then got the same issue bringing the List back FROM the WebService. The solution is to define a new ArrayList for the results, then use AddRange like so:Dim results As ArrayList; results.AddRange(webQuote.makeQuoteFromQuoteInputs(quoteValues.ToArray()))
Gargravarr
A: 

Thanks to everyone who helped but I managed to find the answer. The issue relates to VB.Net's handling of WebService object passes; nothing to do with the C#. As ck said, I had to call '.ToArray()' on the ArrayList when I passed it to the WebService, but then had to use 'AddRange()' on a fresh ArrayList to get the results into it. Code is as follows:

Dim results As New ArrayList;
results.AddRange(webQuote.makeQuoteFromQuoteInputs(quoteValues.ToArray()))

Or generically:

Dim a as New ArrayList;
a.AddRange(webService.Method(sendingAL.ToArray()))
Gargravarr