Consider a WCF service method that returns a generic list as follows:
public List<Employee> GetAllEmployees()
{
//code details here....
//returning a generic List<Employee>
}
On Client-side, if we try to access returned value of that web service method as follows:
MyServiceClient client = new MyServiceClient();
List<Employees> employeeList = client.GetAllEmployees();
We will face following error:
Cannot Implicitly convert type 'MyService.Employee[]' to System.Collections.Generic.List<MyService.Employee>.
Actually, Collections are exposed as array in Service metadata. Generic lists from a WCF service method will be returned as arrays, so we need to do some extra steps to get List<Employee> on client-side.
While adding a service reference, click on "Advance" button. It will open "Service Reference Settings" window. On this window, choose appropriate option for Collection Type i.e. System.Collections.Generic.List.
Now following code will run smoothly without any issue.
List<Employees> employeeList = client.GetAllEmployees();
Related WCF Service Tutorial: