Reputation: 4943
I have a webservice that returns a list of "Clinics" near a certain lat/long. However, in my calling web, I can't compile as an error is occuring on the following code.
private static List<Clinic> GetClinicsNearLocation(Coordinate coordinate, int searchDistance)
{
var wsDental = new ProviderLocation_Dental();
List<Clinic> clinics = wsDental.GetSearchResults(
coordinate.Latitude, coordinate.Longitude, searchDistance);
return clinics;
}
The error is "Cannot convert expression type 'com.dev.webservices.Clinic[]' to return type 'System.Collections.Generic.List 'com.dev.services.dev.Clinic'"
Any ideas as to why?
Here is the web service's method:
public List<Clinic> GetSearchResults(string latitude, string longitude, int searchDistance)
{
var results = Clinic.GetClinicsNearLocation(latitude, longitude, searchDistance);
return results;
}
Upvotes: 0
Views: 5058
Reputation: 13175
The issue is the service reference in your website. Try this:
Right click the service in Service References
-> Configure Service Reference
-> in the Data Type group
-> change the Collection type to System.Collections.Generic.List
-> ok
Make sure to right click the service reference and Update Service Reference.
Upvotes: 2
Reputation: 25775
Almost certainly because the GetSearchResults()
returns an array of Clinic
objects rather than a generic List<Clinic>
.
You may need to fill the List manually with the Array elements or use the constructor overload that accepts an IEnumerable<Clinic>
(as illustrated by @Darin and @McAden).
Upvotes: 0
Reputation: 13972
wsDental.GetSearchResults is returning an array (Clinic[])
You should be able to do:
List<Clinic> clinics = new List<Clinic>(wsDental.GetSearchResults(coordinate.Latitude, coordinate.Longitude, searchDistance));
Upvotes: 0
Reputation: 12399
Because wsDental.GetSearchResults
return type isn't a List.
Try:
private static com.dev.webservices.Clinic[] GetClinicsNearLocation(Coordinate coordinate, int searchDistance)
{
var wsDental = new ProviderLocation_Dental();
com.dev.webservices.Clinic[] clinics = wsDental.GetSearchResults(coordinate.Latitude, coordinate.Longitude, searchDistance);
return clinics;
}
Upvotes: 0
Reputation: 1038710
It seems that the webservice method is defined as follows:
Clinic[] GetSearchResults(coordinate.Latitude, coordinate.Longitude, searchDistance);
If you want to convert an array to a list you can do the following:
List<Clinic> clinics = new List<Clinic>(wsDental.GetSearchResults(coordinate.Latitude, coordinate.Longitude, searchDistance));
or using ToList extension method:
List<Clinic> clinics = wsDental.GetSearchResults(coordinate.Latitude, coordinate.Longitude, searchDistance).ToList();
Upvotes: 5