{
//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 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 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 employeeList = client.GetAllEmployees();
Hopefully this short WCF Tutorial will resolved the issue specified above.
Other Related Articles:
Top 10 Interview Questions and Answers Series:
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET AJAX Interview Questions
Thanks dude, It worked