Get array of custom type in Windows store app via Webservice

55 views Asked by At

I'm using webservice in my windows store application and in the web service I have a method that returns an array of Locations which is a custom type. I tried the following code:

ASMXWebServiceReference.WebServiceSoapClient MyASMXWebServiceClient = new ASMXWebServiceReference.WebServiceSoapClient();
ASMXWebServiceReference.RetrieveFollowingLocationsResponse MyFollowingLocations = await MyASMXWebServiceClient.RetrieveFollowingLocationsAsync("[email protected]");
ASMXWebServiceReference.Location[] locations = new ASMXWebServiceReference.Location[];
locations = MyFollowingLocations.Body.RetrieveFollowingLocationsResult;

The location class look like that: http://tinypic.com/r/1z23wv6/8

I get this error:

Error Cannot implicitly convert type 'System.Collections.ObjectModel.ObservableCollection' to 'App9.ASMXWebServiceReference.Location[]'

1

There are 1 answers

0
Jon On BEST ANSWER

You are trying to assign an ObservableCollection type to an array which won't work and caused the exception. You need to convert the ObservableCollection to an array before assigning it to the array property:

locations = MyFollowingLocations.Body.RetrieveFollowingLocationsResult.ToArray();