Reputation: 368
I'm trying to create and consume a web service... I'm using .NET Framework 4.0 (c#). The service exposes a method like this:
public List<object[]> GetData(string strRegion, List<string> lstBrand, List<string> lstColor)
Then on the client application, I declare a list of objects:
List<object[]> lst = new List<object[]>();
... and attempt to fill it like so:
MyService.MyClient os = new MyClient();
lst = os.GetData(myRegionString, myBrandList, myColorList);
... but I get, "Cannot implicity convert type 'object[][]' to 'System.Collections.Generic.List'". What am I doing wrong?
Thanks!
Upvotes: 0
Views: 4084
Reputation: 143
Obviously you return a jagged array, not a generic list of object[]. One solution is already suggested - just change the type of the return value. But what I think is better is to use interfaces everywhere - both the array and the generic list implement IList, so if you make your method to return a value of type IList, and your lst variable is IList as well, then you shouldn't have problems even if your method returns a jagged array.
Upvotes: 0
Reputation: 6549
In the solution explorer, right click your service and do configuration. You may have set the data collection default type to array. You can set it to be a list type. Also, I would rethink sending an object
over a web service. You typically want a well defined data type. I don't think you can even send type object
over a web service.
Upvotes: 3
Reputation: 71573
The MyClient.GetData() method is returning a jagged array. To convert this array into a list, you should be able to use the ToList() method from the System.Linq namespace:
lst = os.GetData(myRegionString, myBrandList, myColorList).ToList();
Upvotes: 0
Reputation: 7605
Try
MyService.MyClient os = new MyClient();
lst = os.GetData(myRegionString, myBrandList, myColorList).ToList();
Lists will get serialized into arrays as they are passed from the web service to the client, so you'll need to convert it back to a list again.
Upvotes: 2