Take the 2-minute tour ×

I've created a WebMethod that I want to access using a Silverlight application. My problem is that the information I want to send is in the form of a datatable and Silverlight doesn't support System.Data.

This is how my WebMethod looks like so far.

    private string[,] ListAllUsers()
        UserUtility util = new UserUtility();
        var allUsers = util.GetAllUsers();
        string[,] data = new string[allUsers.Rows.Count,allUsers.Columns.Count];
        int r = 0;
        int c = 0;
        foreach (DataRow row in allUsers.Rows)
            foreach (DataColumn column in allUsers.Columns)
                data[r, c] = Convert.ToString((row[column]));
        return data;

I understand that some sort of serialization is involved? Would like to know the best way to get this information to my silverlight application so I can present them.

share|improve this question
I know too little to answer, but I think there should be a way to serialize the data with a common practice. Hope someone better answers your question! –  Phil Mar 25 '11 at 13:36
What do you mean by "information is in the form of a datatable"? You want to return the dataColumn itself or it's content? –  The_Black_Smurf Mar 25 '11 at 17:40
I think wardh is asking for the best practice method of sending a datatable through a web service. I'd like to know this too, is the best way to use a jagged array or is there some easier way to use datatables with a web service? Maybe some sort of generic XML-conversion? –  Phil Mar 26 '11 at 12:12

1 Answer 1

up vote 1 down vote accepted

If you want you can try this http://chunktransporter.codeplex.com/ ...

Otherwise you can try to work with xml.linq... Look if this can help you


Function DoWork(ByVal param As String) As XElement

Execute XML Sql query (Retrieve XML results)

"SELECT ('AlarmType' as 'Alarm/@Type','Description' as 'Alarm/@Description' "from Table FOR XML PATH(''),type) FOR XML PATH('Alarms')"

Dim cns As New SqlConnection(My.Settings.CS)
Dim sql As String = My.Settings.QMAlarmToTacitate
Dim sqlCmd As New SqlCommand(sql, cns)
Dim result = sqlCmd.ExecuteScalar
Dim s = result
Dim res = (XElement.Parse(result))
Return res

Silverlight App

Dim wc As New WebClient
AddHandler wc.DownloadStringCompleted, AddressOf DetailDw
wc.DownloadStringAsync(New Uri("http://myservice.com/service.svc/MyFunction?param1=11111&param2=aaaaa&paramN=nnnn", UriKind.RelativeOrAbsolute))

Private Sub DetailDw(ByVal sender As Object, ByVal e As DownloadStringCompletedEventArgs)
If IsNothing(e.Error) Then
Dim x As Xml.Linq.XElement = Xml.Linq.XElement.Parse(e.Result)
End if

share|improve this answer

Your Answer


