Peter McG's Weblog

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

Posts Tagged ‘Samples’

Silverlight 2 Samples Updated

Posted by petermcg on October 21, 2008

The samples and links to demos on this blog have been updated to be compatible with the release of Silverlight 2.  These projects are typically the result of my curiosity or a desire to unearth benefit from a newly available feature in Silverlight 2.  If they are useful for others so much the better, if not there are certainly lots of other Silverlight 2 samples available elsewhere.

It has always been my intention to make these demos available without any restriction with the release of Silverlight 2, feel free to make use of them however it may benefit you:

Silverlight 2 Pie/Doughnut Chart Demo

Silverlight 2 Polling Duplex Demo – Part 1 : Architecture

Silverlight 2 Polling Duplex Demo – Part 2 : The Server

Silverlight 2 Polling Duplex Demo – Part 3 : The Client

Silverlight 2 Initialization Parameters Demo

Silverlight 2 Stock List Demo – Part 1 : XML file to DataGrid via LINQ to XML

Silverlight 2 Stock List Demo – Part 2 : XML file to DataGrid via WCF

Silverlight 2 Stock List Demo – Part 3 : Making the Grid Tick with Server Deltas via Sockets

The upgrade process was largely painless for me, the main change that sticks in my mind is accounting for the change in case of the GridLinesVisibility property on the DataGrid.  The pie chart live-demos have been updated but are hosted on Silverlight Streaming which does not yet fully support the released version of Silverlight 2, I expect this to change in the near future.

Changes of interest with regard to the Polling Duplex sample include that the server System.ServiceModel.PollingDuplex.dll assembly installed as part of the Silverlight 2 SDK is no longer contained in a folder titled ‘Evaluation’ but instead in the same folder as System.Web.Silverlight.dll.  This corresponds with the summary note here that this technology is no longer in evaluation and can now be used and deployed as part of Silverlight 2 production applications.  Finally, the previously mentioned DuplexReceiver functionality is now manifest as described here and demonstrated here as part of the Silverlight 2 RTW Web Services samples.


Posted in Silverlight | Tagged: , | 4 Comments »

Silverlight 2 RC0 Polling Duplex Evolution

Posted by petermcg on September 30, 2008

The release of Silverlight RC0 presents some minor breaking changes for applications using the polling duplex support provided in Beta 2.

The summary of these changes taken from the full Breaking Changes Since Beta 2 document is as follows:

  • PollTimeout setting on the server side (PollingDuplexHttpBinding and PollingDuplexBindingElement) has been renamed to ServerPollTimeout

  • PollTimeout setting on the PollingDuplexBindingElement (client side) has been renamed to ClientPollTimeout.

  • PollTimeout setting on the PollingDuplexHttpBinding (client side) has been cut. In most scenarios, it should not be necessary to change this. If a change is necessary, it can be achieved through the ClientPollTimeout on the PollingDuplexBindingElement.

  • Client-side support has been cut from the non-Silverlight (server-side) polling duplex assembly (i.e. BuildChannelFactory will throw a NotSupportedException). That is, in RTM, the client side for polling duplex must be Silverlight (and the server side must be the regular .NET Framework, but this restriction was already in place in Beta2).

  • Default timeouts have been changed for the Duplex channel. For most common scenarios, the new out-of-the-box defaults should be appropriate and there is no need to change them.

  • An error (404) on a polling request will cause the duplex channel to fault.

  • Various invalid messages used to be ignored by the Duplex stack but will now be rejected.

  • If any HTTP error (404,500,…) is encountered during a SOAP call, a CommunicationException is now thrown instead of a ProtocolException.

Earlier this month I put together a series of posts representing somewhat of a deep-dive into the WCF Polling Duplex support in Silverlight 2 Beta 2.  The series is in three parts covering Architecture, The Server and The Client and will still be largely relevant.  The source code for a Beta 2 sample application discussed across parts two and three is available for download.

I will be on vacation over the next week-and-a-bit and won’t be able to respond to emails/queries immediately but I do fully intend to update the polling duplex sample application to account for these breaking changes when I return.  Applications built with Beta 2 will not run on final runtime builds so I will also update the other samples available on this blog including the pie/doughnut chart and Sockets samples in the near future.

Posted in PollingDuplex, Silverlight, WCF | Tagged: , , | 3 Comments »

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.

Posted in Pie Chart, Silverlight, Sockets, WCF | Tagged: , | 3 Comments »