Information on using Silverlight 2

Aug 21, 2008 at 8:42 PM
FWIW, the Silverlight section of the user guide is no longer quite accurate (the info looks to be a year old, or at least older than MIX08)

Easiest way to get Silverlight 2 Beta 2 going on a Facebook canvas page is to use an ASP.NET host, and then use the asp:Silverlight control. Rather than mess with hidden fields, you can use the initParams like this (assuming you have changed the default name from xaml1 to silverlightControl).

            string initParams = string.Format("userId={0},sessionKey={1}", api.UserId, api.SessionKey);

            silverlightControl.InitParameters = initParams;

In the Silverlight app, you can then access the values like this (in app.xaml.cs):

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // Load the main control
            this.RootVisual = new Page();

            string userid = e.InitParams["userId"];
            string sessionKey = e.InitParams["sessionKey"];

        }

That approach removes the need for hidden fields, as well as the need to put your api key and secret inline in the page (that seemed like a pretty bad idea to me)

You don't need to use JSON serialization for the services, you can use the "Silverlight-enabled WCF Service" template, or just use any WCF basicHttpBinding (or asp.net SOAP, or any other SOAP 1.1) based service. If you use WCF, you can use nice strong types with pretty much any members you may need.

You will still need to follow other suggestions regarding passing the userid and sessionkey up to the service for each call. However, I have the service keep an awareness of the application id/api key and secret so I don't need to pass that around via Silverlight. That also cuts down on two parameters.

Pete

Coordinator
Aug 21, 2008 at 10:08 PM
great info.  Thanks.  I will get the documentation updated for the next drop of 2.0