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.
[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
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 WebClientAddHandler wc.DownloadStringCompleted, AddressOf DetailDw
wc.DownloadStringAsync(New Uri("http://myservice.com/service.svc/MyFunction?param1=11111¶m2=aaaaa¶mN=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