WCF Service list
-
WCF Service returns List. I call from wpf app and have User class which contains the same properties as Employee class in wcf service. Eservice EmployeeSrvc = new Eservice(); List lstUser= new List(); lstEmployee = EmployeeSrvc.GetEmployeeDetails(); I get the error "Cannot implicitly convert type .." I am not sure how to convert the WCF return list to List in my wpf app. Please help!
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates
-
WCF Service returns List. I call from wpf app and have User class which contains the same properties as Employee class in wcf service. Eservice EmployeeSrvc = new Eservice(); List lstUser= new List(); lstEmployee = EmployeeSrvc.GetEmployeeDetails(); I get the error "Cannot implicitly convert type .." I am not sure how to convert the WCF return list to List in my wpf app. Please help!
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates
Hi, "List" is a generic type which means, it provides functionality, which can be applied to abitrary (other) types. That's why you can't have "List" as the return type of a webservice (or just any method), but List<T> where "T" is another type. If you have two instances of List<T> and the involded "T"s are different, the List-types are not convertible (neither implicitly nor explicitly). So, if you have
List lstUser = new List();
you can't assign the result of
List lstEmployee = EmployeeSrvc.GetEmployeeDetails();
This is true for .Net until 3.5; in .Net 4 MS has made some improvements. Just search for "covariance"/"contravariance". If "Emplpoyee" and "User" have the same properties, you should just use one class (e. g. "Person"). Another possible solution could be to loop through the results of the service (employees) and create and add new users. Cheers Jürgen
If this answer saves you some time, please spend a bit of it to vote.
-
Hi, "List" is a generic type which means, it provides functionality, which can be applied to abitrary (other) types. That's why you can't have "List" as the return type of a webservice (or just any method), but List<T> where "T" is another type. If you have two instances of List<T> and the involded "T"s are different, the List-types are not convertible (neither implicitly nor explicitly). So, if you have
List lstUser = new List();
you can't assign the result of
List lstEmployee = EmployeeSrvc.GetEmployeeDetails();
This is true for .Net until 3.5; in .Net 4 MS has made some improvements. Just search for "covariance"/"contravariance". If "Emplpoyee" and "User" have the same properties, you should just use one class (e. g. "Person"). Another possible solution could be to loop through the results of the service (employees) and create and add new users. Cheers Jürgen
If this answer saves you some time, please spend a bit of it to vote.
Jurgen, Thanks a ton! I used the same List which is used in the WCF service instead of creating List in my application separately like below. Eservice EmployeeSrvc = new Eservice(); List lstEmployee = new List(); lstEmployee = EmployeeSrvc.GetEmployeeDetails();
------------------------------------------------------------ "The only true wisdom is in knowing you know nothing." --Socrates