views:

258

answers:

5

Hi- 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;
}
+2  A: 

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();
Darin Dimitrov
Thanks. Not sure how the web service would return an array as here is the definition: public List<Clinic> GetSearchResults(string latitude, string longitude, int searchDistance) { var results = Clinic.GetClinicsNearLocation(latitude, longitude, searchDistance); return results;}Any reason why it would return an array with the method above?
asp316
There's no such thing as List in the WSDL specification. This is a .NET specific type. Imagine you have a Java client. In WSDL there are arrays. This means that your List is automatically converted to an array when you generate your client proxy.
Darin Dimitrov
A: 

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;
}
marcc
A: 

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));
McAden
A: 

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).

Cerebrus
A: 

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.

blu