Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. WCF Service list

WCF Service list

Scheduled Pinned Locked Moved WPF
csharphelpwpfwcftutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DotNetXenon
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • D DotNetXenon

      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

      J Offline
      J Offline
      Jurgen Rohr
      wrote on last edited by
      #2

      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.

      D 1 Reply Last reply
      0
      • J Jurgen Rohr

        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.

        D Offline
        D Offline
        DotNetXenon
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups