Peter McGrattan’s Weblog

Silverlight, WCF, ASP.NET, AJAX, Graphics, RIA

Samples Updated to Beta 2

Posted by petermcg on June 10, 2008

The API and documentation changes and the fact that Beta2 will not run applications that target Beta1 has obliged me to update links and all the samples previously posted on this blog such as the Pie Chart and Stock List Demo.  From this point on all posts will target Silverlight 2 Beta 2.

I started with a brand new Beta 2 solution when updating each sample to keep things clean.  The changes required to make the the new Pie Chart Solution work included updating the parameter list for the calls to the static Register method for the Dependency properties in the PieChart class now they require an instance of the PropertyMetadata class; a similar change to the Storyboard.SetTargetProperty method calls in PieLayoutManager that now require an instance of the PropertyPath class.  The need to add the MouseEnter animation Storyboard to the resources of the PieChart Canvas is removed thanks to the new support for the ability to create Storyboards in code that can animate parts of the render tree without having to be added to it.

The Stock List Demo Part 3 sample required the same changes for Storyboard.SetTargetProperty and also benefited from the fact that Storyboards created in code no longer have to be added to the Resources of a FrameworkElement for the stock highlight animations to work.  Other changes I ran into included that EventHandler<T> now requires T to inherit from EventArgs, the DataGrid’s AutoGenerateColumns is now true by default, displays itself using a smaller font by default and supports auto-sized columns.

The biggest change to the Stock List Demo project for Beta 2 was the new policy requirements around creating a Sockets server which have been implemented in the updated sample :

Console.WriteLine("Accepting Policy Requests...");

// Read policy file
byte[] policyBytes = File.ReadAllBytes("PolicyResponse.xml");

using (Socket client = policyListener.AcceptSocket())
    Console.WriteLine("Policy Request Accepted...");

    // Get policy request header
    byte[] buffer = new byte[1024];
    int bytesReceived = client.Receive(buffer);

    // Basic check of request header
    string header = Encoding.UTF8.GetString(buffer, 0, bytesReceived);

    if (header == "<policy-file-request/>")
        client.Send(policyBytes, 0, policyBytes.Length, SocketFlags.None);

Please download the latest version for a substantial demonstration of many areas of Silverlight development including Socket interaction that complies with the new policy changes in Silverlight 2 Beta 2.

As part of the upgrade I did run into this issue of not being able to discover a WCF web-service in the same solution after installing Beta 2 when creating the new solution for Stock List Demo 3.  The workaround at the end of the thread here solved the problem.

Please feel free to download the updated samples and as usual let me know any thoughts by adding a quick comment.


3 Responses to “Samples Updated to Beta 2”

  1. Hi Peter,

    This is a fantastic example of many of the new facilities Silverlight 2 offers in the way of push communications and works very nicely, however, I need to replicate this functionality in a real world scenario whereby we cannot lose a single packet and upon further investigation into this demo solution it seems that we ignore (by way of catch all) packets that are sent from the server that do not contain one single serialized object (please see screenshot below). I looked into it more and was under the impression that the AutoFlush should handle partial objects etc but this does not seem to be the case.

    I was hoping you could help me on this one as we will be expecting to recieve up to 100 messages per second in the Silverlight Client so in this proof of concept stage it would be great to get this working and I think your sample solution here is 95% of what we are trying to achieve.

    Thank you and I look forward to hearing your thoughts.

    Best Regards,

  2. Nevermind, sorted it, I wrote a method to Extract multiple messages from the buffer retaining any overflow for the next read.

    Thank you and keep the posts coming – extremely informative and useful!

    Best Regards,

  3. Peter McGrattan said

    Hi Martin,

    Thanks for your comments on the sample and the blog in general, I got your email this morning in my time zone and have fixed the problem and updated the code download links.

    I had actually been meaning to fix that problem for a while, a comprehensive sample should demonstrate all packets being received from the server so thanks for the excuse to fix it!

    Hope this helps with the proof of concept… šŸ™‚



Sorry, the comment form is closed at this time.

%d bloggers like this: