Link to home
Start Free TrialLog in
Avatar of CipherIS
CipherISFlag for United States of America

asked on

WCF Get Data from database as List<>

Can anyone provide me a simple example of how to get data using WCF from a database preferably returning a List<>.  I have a SPROC set up in the database which will return the data.

Thanks
Avatar of kaufmed
kaufmed
Flag of United States of America image

Retrieving data from a DB is no different in WCF than it is in a WinForms or Console application. As far as turning that data into a List, use the ExecuteReader method of your command object. Then it is simply a matter of continually calling Read against the resulting DataReader until it returns false, and within the loop add each datum to your list.

You can simply specify the return type of your WCF method as List<XXX> (I'm guessing XXX will be string for your purposes). The runtime will take care of serializing that object into XML for you.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CipherIS

ASKER

Thanks this template helped me create my own.
template was able to help me create a WCF per my requrements