Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Returning multiple tables from a single WCF web method
4 replies. Latest Post by BigDubb on November 20, 2008.
(0)
davedrat
Member
21 points
19 Posts
11-17-2008 4:28 AM |
Hi folks,
I want to return a number of tables of different shapes from a database using a single stored procedure.
I have successfully set up a wcf web service which returns a single table without any problems. My silverlight app is using this data successfully.
The code I am using in my service is as follows:
End
To change it to use multiple tables I have tried the following:
1. Edit the stored procedure to return two different tables
2. Drag the new table structures on to my .dbml designer.
3. Edit the partial class to have a function which returns multiple results. (code below)
<ResultType(
My problem is I can't figure out how to return these multiple results from the webservice, or how to consume them in the Silverlight app.
Any help is greatly appreciated.
Thanks
shamrat231
Contributor
4639 points
591 Posts
11-17-2008 5:20 AM |
Run multiple service to get multiple result.
for example in. Service1.GetCompleted method...when you get e.result,assign it to something and then run the next wcf service. In this way you are getting multiple result from ecf.
i have used it in this way on my current project and it worked.
and if this post was helpful then please 'Mark as Answer' - many thanks
Sharker Khaleed MahmudSoftware Developer(MCP,MCTS,MCPD[web])
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
11-17-2008 6:58 AM |
Thanks Shamrat,
I can see that your suggestion would work, but it involves making lots of round trips to the server and back.
Does anybody know of a more efficient way to acquire multiple tables in a single trip to the database?
cheers
Amanda W...
All-Star
17241 points
1,466 Posts
11-20-2008 6:49 AM |
Hi,.
You can try to refer this thread: How to Display DataSet in Silverlight DataGrid
BigDubb
65 points
77 Posts
11-20-2008 10:27 AM |
Have you considered creating your own object to house the datasets to be returned. maybe something like this:
[ServiceContract] public interface IService { [OperationContract] MyResults GetMyResultSet(object SomeParameter); } [DataContract] public class Employee { string _FirstName; string _LastName; string _Title; [DataMember] public string FirstName { get { return _FirstName; } set { _FirstName = value; } } [DataMember] public string LastName { get { return _LastName; } set { _LastName = value; } } [DataMember] public string Title { get { return _Title; } set { _Title = value; } } } [DataContract] public class Book { string _Title; string _Author; string _ISBN; [DataMember] public string Title { get { return _Title; } set { _Title = value; } } [DataMember] public string Author { get { return _Author; } set { _Author = value; } } [DataMember] public string ISBN { get { return _ISBN; } set { _ISBN = value; } } } [DataContract] public class MyResults { List _Books; List _Employees; [DataMember] public List<Book> Books { get { return _Books; } set { _Books = value; } } [DataMember] public List<Employee> Employees { get { return _Employees; } set { _Employees = value; } } }