Title: Microsoft Silverlight 4 Data and Services Cookbook
Author : Gill Cleeren, Kevin Dockx
ISBN: 1847199843 - 978-1-847199-84-3
Packt Publishing April 2010
Buy/Pre-Order from Packt
Microsoft Silverlight 4 Data and Services Cookbook
Packt publishing has just released a new Silverlight 4 book, focusing on Data and Services in Silverlight 4. The functionality that now exists, around these areas in Silverlight 4, now makes it a very compelling technology for building business applications. Not only can Silverlight deliver rich media services, and viral games, it also has extensive functionality around consuming services, rendering and editing data, via a series of rich controls, and Validation. So it’s not surprising this title was released to bring all these elements together in a ‘Recipe Book’
That’s right, this book is not a traditional ‘read though’, but more a collection of 85 how-tos, organized into 10 chapters. So for this review I tried a different approach…
Before opening the book I made-up 12 scenarios which, as a user, I may want to solve, to see how the book fares in my ‘Challenges’
1) I have a Boolean property to which I need to Databind to a visual elements Visibility property and have a mismatch
2) I need to save my data somewhere locally for offline scenarios
3) I need to call a third party web-site to consume a service, but get an exception
4) I’d like to change the DataForm to be customized in Edit View
5) My Website has authentication and I’d like to exploit the Application services for Roles/Profile information in my Silverlight Application
6) I want to use MVVM, and in particular want to understand Commanding
7) I need to make a WebRequest and pass user credentials in the call
8) I’m hearing a lot about WCF RIA services – how does this make my life easier
9) I have a collection of items, and control over the collection type, what’s my best approach for DataBinding
10) I want to bind my Slider to the Angle property of a RotateTransform – Can I do this in Silverlight 4
11) If the value of the object I am binding to is Null how can I provide a default value?
12) The Silverlight Grid supports ‘*’ for column sizes, how do I do this in the DataGrid
Chapter 1 – Nuts and bolts of Silverlight 4
The opening chapter serves as a bit of a primer for people who haven’t really used Silverlight – It explains the tools you need, and the architecture of a Silverlight. Even as a opening chapter, I felt the coverage was good here, covering some of the issues, such as configuring MIME types on IIS when deploying the application, and also you can change the .XAP extension to .ZIP and it will still work.
Challenges Complete: 0/12
Chapter 2 - Databinding
In Chapter 2 we delve straight into Databinding, with a well written and concise overview, before getting into a Simple example. I like how the book highlights the differences between Silverlight 2/3 and 4 (for example FrameworkElement v DependencyObject). The opening code sample was a bit too long (4 pages of XAML), but the example worked well. We then have an example of Element to Element binding, before moving on to binding to collections, the different modes (OneTime,OneWay,TwoWay), and also programmatically accessing the DataContext within a button click handler. The chapter is then rounded off by showing Databinding in Expression Blend and how to generate Sample data to appreciate design layout.
Challenges Complete: 1/12
Chapter 3 – Advanced DataBinding
The advanced Databinding gets off to a cracking start with an early challenge completed, explaining about Converters in Silverlight, and swiftly follows up with a recipe for CommandParameters, and BindingBase properties such as StringFormat, TargetNullValue and FormatValue. It then talks about validation and the IDataErrorInfo and INotifyDataErrorInfo interfaces and creating a DataTemplate for the ListBox control. A recipe brings them all together at the end of the chapter.
Challenges Complete: 4/12
Chapter 4 – The DataGrid.
The DataGrid is a powerful control in the Silverlight SDK, and extremely valuable in Data Scenarios. This Chapter kicks off with a sample implementation and highlights the additional assemblies which get including in the XAP package, and the support for UI virtualization. It then moves on with a sample for Updating, Insertion and Deletion of items, before moving on to Sorting and Grouping, all of which are supported by the DataGrid Control. A second control, the DataPager is then added to provide paging support, and the receipe here, highlights the different flavours of default UI for the DataPager. This Chapter also demonstrates the ability to customize the fields using the DataGridTemplateColumn. This chapter scores a late strike with an explanation of column sizing, and support for ‘*’ in the Silverlight 4 DataGrid, before the final recipe highlights a master/detail view scenario.
Challenges Complete: 5/12
Chapter 5 – The DataForm
A quite often overlooked control, the DataForm, is available in the Silverlight Toolkit, which will, given an object (or collection of objects), render the data form for view/edit/deletion, complete with customization and validation support. So it’s not surprising this control has a chapter to itself. The first recipe shows the true power of this control, with a simple example, before changing the Data source to be a collection, and using annotations to change the prompts and descriptions. It then goes on to discuss how you can template the control in Read/Update states, and then demonstrates using Blend to change the overall control, before finishing with Validation of fields.
Challenges Complete: 6/12
Chapter 6 – Talking to Services
“No Silverlight application is an island” – is what I like to say, and Chapter 6 tells us how to get off the island by talking to Services. It’s nice the first recipe is ASMX, as that’s a common question I get asked at user group presentations. It then also demonstrates calling a service to update data, before moving on to talk about Cross Domain calls and the impact on Silverlight, in both In Browser, and out-of-browser elevated Silverlight applications. The chapter then provides a recipe for using the HttpWebRequest to consume an XML feed. It’s nice how each example here, is simple yet covers a different aspect, asmx, wcf, objects, XML, request types. As RSS consumption example demonstrates the SyndicationFeed object, before a demonstration of aggregation of multiple feeds. There’s a demonstration of Sockets, before a couple of recipes on Talking to Azure.
Challenges Complete: 7/12
Chapter 7 – Talking to WCF and ASMX Services
Chapter 7 is a deep dive into WCF and ASMX, covering consuming and handling faults, increasing performance with Binary XML and using Duplex communication. It then provides recipes on Debugging, Encrypting and Security of messaging, and creating service references from the command line.
Challenges Complete: 7/12
Chapter 8 – Talking to Rest and DataServices
Chapter 8 focuses on talking to REST based services in both XML and JSON format. It then talks about ‘ADO.NET Data Services’ as was, before focusing on examples which consumes images from Flickr and content from Twitter. There’s a nice little diversion onto Out-Of-Browser Elevated applications and awareness of being offline, or installed before showing how to inject authentication details into the WebClient
Challenges Complete: 8/12
Chapter 9 – Talking to WCF RIA Services
WCF RIA Services is a framework to make building business applications easier, and is the focus of Chapter 9. The first recipe gets us up and running with WCF RIA Services, before bringing in an example of Sorting and Filtering to a DataGrid. It then covers the updating of data back to the database and using the authentication services to track the user using the application and securing the services on the webserver. It then looks at the DomainDataService. I would have liked to see a ‘custom’ entity in this section, and working with Stored Procedures.
Challenges Complete: 8/12
Chapter 10 – Converting your existing applications to user Silverlight
Chapter 10 is a mixed bag of items, starting with using WCF to call a Stored Procedure on the server and using LINQ to SQL and the Entity Framework in your existing Silverlight application. It wraps up with using the Application Services in ASP.NET to provide Authentication, Roles and Profile support
Challenges Complete: 9/12
A score of 9/12 in the Challenge is a great result; the only missing items were persisting/reading values and objects to and from Isolated Storage (very briefly touched on in Chapter 6). There was no Commanding or MVVM covered, which is becoming a common requirement in the marketplace, and I’d liked to have seen a custom entity in the RIA services section. Having said that, these are niggles and it’s impossible to cover everything in one book.
Microsoft Silverlight 4 Data and Services Cookbook is a great publication, and worthy of a place any Silverlight developers bookshelf. The formula of ‘recipes’ works well, with well explained, yet simple examples covering almost everything you’d ask when starting out building business applications in Silverlight. It highlights Silverlight 2 and Silverlight 3 functionality differences, yet is right up to date on Silverlight 4.