Sending complex typed data from web service to SilverLight client – Part III
Here I'll sum this part which is Serialize the object for the SilverLight
component and operate method inside it to bind the data.
Step 5 - Serialize the data for the SilverLight component
And here is the code converting the objects
var slEmployees = new Array(result.length);
for (var index = 0; index <result.length; index++)
var newEmployee =
"FirstName" : result[index].FirstName,
"LastName" : result[index].LastName,
"EmployeeNumber" : result[index].EmployeeNumber
slEmployees[index] = newEmployee;
//Serialize the employees
var slSerEmployees = Object.toJSON(slEmployees);
//Bind the data on the silverlight component
The method Object.toJSON is taken from the file Prototype.js written by
Sam Stephenson and distributed freely on http://www.prototypejs.org/
And Finally - Let's insert our SilverlLight control into our test page:
<asp:Silverlight ID="Xaml1" runat="server"
Version="2.0" Width="100%" Height="100%" />
Summary: In order to have complex typed data sent from
need to do the following:
1. On your SilverLight project code - write a class with data corresponds
to the data you get from your server.
3. Operate method from your page on your SilverLight control to bind
the serialized data received.
I've attached the SilverLight project's code so you can get started
with your server & mediator easily.