开发者

How to receive datatable via WebService call in a silverlight application?

开发者 https://www.devze.com 2023-02-19 13:12 出处:网络
I\'ve created a WebMethod that I want to access using a 开发者_如何学PythonSilverlight application. My problem is that the information I want to send is in the form of a datatable and Silverlight does

I've created a WebMethod that I want to access using a 开发者_如何学PythonSilverlight 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.

[WebMethod]
    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)
        {
            r++;
            foreach (DataColumn column in allUsers.Columns)
            {
                c++;
                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.


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


WebService

<OperationContract()>
<WebGet()>
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)
cns.Open()
Dim result = sqlCmd.ExecuteScalar
Dim s = result
Dim res = (XElement.Parse(result))
cns.Close()
cns.Dispose()
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

0

精彩评论

暂无评论...
验证码 换一张
取 消