Error converting to list in WCF

3

This is my code:

My service implementation .svc

  public List<string> getClientes()
    {
        using (var context = new Model.CivarTransporteModelContainer())
        {
            return context.Cliente.Select(x => x.CLNombre).ToList();
        }
    }

My service interface .cs

 [OperationContract]
    List<string> getClientes();

Web application

if (Request.QueryString["getClientes"] != null)
        {

            CivarTransporteService.View.CatalogsService wsclient = new CivarTransporteService.View.CatalogsService();
            List<CivarTransporteService.View.CatalogsService> clientList =wsclient.getClientes().ToList();

        }

I'm having an error in the = wsclient.getClientes().toList(); part

Cannot implicitly convert type System.Collections.Generic.List<string> to
 System.Collections.Generic.List<CivarTransporteService.View.CatalogsService>
    
asked by jm167 21.01.2016 в 22:14
source

2 answers

2

You are returning a list of type List<string> which when you receive the data in the web application, you are storing them in a list of type List<CivarTransporteService.View.CatalogsService> generating the error by type, you should receive the data in a list of type List<string> .

Greetings

    
answered by 21.01.2016 в 22:18
2

Is that you're trying to assign a List<string> returned by getClientes() to a list of CatalogsService

You should check the assignment of data types

The correct thing would be

List<string> clientList = wsclient.getClientes();

Note: the .ToList() of the end is not required because getClientes() already returns this type of list

    
answered by 21.01.2016 в 22:18