Skip to main content

Microsoft Silverlight

Answered Question Returning multiple tables from a single WCF web methodRSS Feed

(0)

davedrat
davedrat

Member

Member

21 points

19 Posts

Returning multiple tables from a single WCF web method

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:

Public Class Service1

Implements IService1

Private rdc As ResourceDataContext

Public Sub New()

rdc = New ResourceDataContext

End Sub

Public Function mp_GetResourceRecords() As IEnumerable(Of ResourceRecord) Implements IService1.mp_GetResourceRecords

 

Return dc.mp_GetResourceRecords().GetResult(Of ResourceRecord)()

End Function

End Class

 

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)

<FunctionAttribute(Name:="dbo.mp_GetResourceRecords")> _

<ResultType(GetType(ResourceRecord))> _

<ResultType(GetType(ProjectRecord))> _

Public Function mp_GetResourceRecords() As IMultipleResults

Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo))

Return CType(result.ReturnValue, IMultipleResults)

End Function

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
shamrat231

Contributor

Contributor

4639 points

591 Posts

Re: Returning multiple tables from a single WCF web method

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 Mahmud
Software 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.

Dhaka, Bangladesh
LinkedIn :: SL Profile :: Blog

davedrat
davedrat

Member

Member

21 points

19 Posts

Re: Returning multiple tables from a single WCF web method

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 Wang - MSFT
Amanda W...

All-Star

All-Star

17241 points

1,466 Posts

Re: Returning multiple tables from a single WCF web method

Hi,.

You can try to refer this thread:  How to Display DataSet in Silverlight DataGrid

Amanda Wang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

BigDubb
BigDubb

Member

Member

65 points

77 Posts

Answered Question

Re: Returning multiple tables from a single WCF web method

 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; }
}
}
 
With this methodology you can strongly type your result sets to object, then handle the result set when it comes back and bind your datatable to a respective collection of objects.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities