.Net List of SOAP arrays and back to .Net list
In the CarService web service
- I have a class called Car.
- The car has a bunch of properties, i.e. Car.Color.
- CarService has a method called GetCars ().
-
In GetCar, I have a loop that adds a list, you guessed it. Cars.
Dim carList as a new list (from car)
Do While rdr.Read () If rdr.GetValue (1) .ToString (). Length> 0 Then Dim c As Car = new car c.Color = rdr.GetValue (1) .ToString () carList.Add (c) End If Loop
GetCars () returns carList.
I also have another page in another project that uses this data.
Or at least I would like and here's my problem ..
If I do this.
Dim myNewCars As List(Of Namespace.Car) myNewCars = CarServiceProxy.GetCars()
I get:
A value of type '1-dimensional array Namespace.Car' cannot be converted to 'System.Collections.Generic.List (Of Namespace.Car)'.
What would be the best way to convert this 1-dimensional array back to a list of cars?
a source to share
Without changing anything? Use a constructor List<T>
that takes IEnumerable<T>
- so in C # (my VB is small):
List<Car> myNewCars = new List<Car>(CarServiceProxy.GetCars());
If you can make a difference; maybe consider things like using WCF where you can specify the type of the collection (of all methods) - a switch scvutil /collectionType:
. However, moving to the WCF stack is not trivial.
a source to share