arraysweb-serviceswindows-store-appscustom-type

Get array of custom type in Windows store app via Webservice


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("g@g.g");
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[]'


Solution

  • 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();