You are previewing Microsoft Silverlight 5 Data and Services Cookbook.
O'Reilly logo
Microsoft Silverlight 5 Data and Services Cookbook

Book Description

"

Over 115 practical recipes for creating rich, data-driven, business applications in Silverlight 5 using this book and eBook.

  • Design and develop rich data-driven business applications in Silverlight and Windows Phone 7 following best practices using this book and eBook

  • Rapidly interact with services and handle multiple sources of data within Silverlight and Windows Phone 7 business applications

  • Understand sophisticated data access techniques in your Silverlight business applications by binding data to Silverlight controls, validating data in Silverlight, getting data from services into Silverlight applications, using data and services using MVVM techniques and much more!

  • Packed with practical, hands-on cookbook recipes, illustrating the techniques to solve particular data problems effectively within your Silverlight and Windows Phone 7 business applications

  • This book is an update to Microsoft Silverlight 4 Data and Services Cookbook

In Detail

Microsoft Silverlight is a programmable web browser plugin that enables features including animation, vector graphics, and audio-video playback – features that characterize Rich Internet Applications. However, Silverlight is a great (and growing) Line-Of-Business platform and is increasingly being used to build data-driven business applications, both in an out of the browser. It is also the heart of Windows Phone 7 development so developers can leverage their knowledge on Microsoft’s new mobile platform as well. Services enable efficient access to your data, allowing you to draw on multiple sources of data and solve particular data problems. There is very little existing material that demonstrates how to build data-driven, enterprise-ready solutions with the platform. Silverlight 3 and 4 made a big step into Line-Of-Business data services and Silverlight 5 builds further upon this.

In this book, Gill Cleeren, Microsoft Regional Director, Silverlight MVP (former ASP.NET MVP), Telerik MVP at Ordina Belgium and Kevin Dockx, a technical specialist/project leader on .NET web applications and a solution manager for Rich Applications at RealDolmen, focus on showing .NET developers how to get their finger on the pulse of data-driven business applications in Silverlight and Windows Phone 7. What’s more, the upcoming Windows 8 will allow developers to build native, immersive Metro-style applications using XAML & C# - exactly what this book is based upon. In other words, the techniques described in this book also apply to Windows 8.

This book is not a general Silverlight 4/5 overview book; it is uniquely aimed at developers who want to build data-driven applications, based on best practices. It focuses on showing .NET developers how to interact with, and handle multiple sources of data in Silverlight business applications, and how to solve particular data problems following a practical hands-on approach, using real-world recipes. It is a practical cookbook that teaches you how to build data-rich business applications with Silverlight that draw on multiple sources of data. Most of the features covered work both in Silverlight 4 and 5. However, we cover some that are specific to Silverlight 5, which will therefore not work with Silverlight 4. Where this is the case, it is clearly indicated.

Packed with reusable, real-world recipes, the book begins by introducing you to general principles when programming Silverlight. It then dives deep into the world of data and services, covering all the options available to access data and communicate with services to get the most out of data in your Silverlight business applications, whilst at the same time providing a rich user experience. This book also covers topics related to storing data locally as well as explaining how to work with data and services in a Model-View-View-Model (MVVM) architecture. Most of the content is applicable to Windows Phone 7 developers as well; a specific chapter on WP7 development is included in this release. By following the practical recipes in this book, which are of varying difficulty levels, you will learn the concepts needed to create data-rich business applications—from the creation of a Silverlight application, to displaying data in the Silverlight application and applying best practices such as MVVM. Each recipe covers a data services topic, going from the description of the problem, through a conceptual solution to a solution containing sample code.

"

Table of Contents

  1. Microsoft Silverlight 5 Data and Services Cookbook
    1. Table of Contents
    2. Microsoft Silverlight 5 Data and Services Cookbook
    3. Credits
    4. About the Authors
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why Subscribe?
        2. Free Access for Packt account holders
        3. Instant Updates on New Packt Books
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Errata
        2. Piracy
        3. Questions
    8. 1. Learning the Nuts and Bolts of Silverlight 5
      1. Introduction
      2. Getting our environment ready to start building Silverlight applications
        1. How to do it...
        2. How it works...
        3. See also
      3. Creating our first service-enabled and data-driven Silverlight 5 application using Visual Studio 2010
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The solution and project structure
            1. Services
            2. Data binding
        4. See also
      4. Using the workflow between Visual Studio 2010 and Blend 5
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Using source control in Visual Studio 2010 and Blend 5
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. Commonly used terms in TFS
      6. Deploying a Silverlight application on the server
        1. How to do it...
        2. How it works...
          1. Configuration changes on the server
          2. What if the server doesn't allow using XAP?
    9. 2. An Introduction to Data Binding
      1. Introduction
      2. Displaying data in Silverlight applications
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      3. Creating dynamic bindings
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Binding data to another UI element
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Element bindings without bindings
        5. See also
      5. Binding collections to UI elements
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Enabling a Silverlight application to automatically update its UI
        1. Getting ready
        2. How to do it...
          1. How it works...
            1. Single objects
            2. Collections
            3. Cleaning up the code
      7. Obtaining data from any UI element it is bound to
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Using the different modes of data binding to allow persisting data
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
          3. See also
      9. Debugging data binding expressions in Visual Studio
        1. Getting ready
        2. How to do it...
          1. How it works
          2. See also
      10. Data binding from Expression Blend 5
        1. How to do it...
        2. How it works...
      11. Using Expression Blend 5 for sample data generation
        1. How to do it...
    10. 3. Advanced Data Binding
      1. Introduction
      2. Hooking into the data binding process
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The ConverterParameter
          2. Displaying images based on a URL with converters
      3. Replacing converters with Silverlight 5 BindingBase properties
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Validating data-bound input
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Validating data input using attributes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Other uses of data annotations
        5. See also
      6. Validating using IDataErrorInfo and INotifyDataErrorInfo
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Using templates to customize the way data is shown by controls
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Using implicit data templates
        1. Getting ready
        2. How to do it...
        3. How it works
        4. See also
      9. Using the Ancestor RelativeSource binding
        1. Getting ready
        2. How to do it...
        3. How it works
        4. See also
      10. Creating custom markup extensions
        1. Getting ready
        2. How to do it...
        3. How it works
      11. Building a change-aware collection type
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. See also
      12. Combining converters, data binding, and DataContext into a custom DataTemplate
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    11. 4. The Data Grid
      1. Introduction
      2. Displaying data in a customized DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also...
      3. Inserting, updating, and deleting data in a DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also...
      4. Sorting and grouping data in a DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Sorting a template column
        5. See also
      5. Filtering and paging data in a DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also...
      6. Using custom columns in the DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      7. Implementing master-detail in the DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Validating the DataGrid
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also...
    12. 5. Working with Local Data
      1. Introduction
      2. Reading data from and storing data in the isolated storage
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Where's my data
          2. Isolated storage size
        4. See also
      3. Working with IsolatedStorageSettings
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Caching data between different Silverlight applications using isolated storage
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. What about IsolatedStorageSettings?
      5. Using the Sterling database
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Getting Sterling
          2. Creating a database
          3. The Sterling engine
          4. Saving and loading data
          5. Triggers
        4. See also
    13. 6. MVVM
      1. Introduction
      2. Creating a basic MVVM application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Using MVVM Light to enable MVVM applications
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      4. Connecting a View to a ViewModel using a ViewModelLocator
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Connecting a View to a ViewModel using MEF
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Using commands to pass your events to the ViewModel
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. See also
      7. Communicating between different ViewModels
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Leveraging a messenger to wrap application-wide messages
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    14. 7. Working with Services
      1. Introduction
      2. Connecting and reading from a standardized service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Persisting data using a standardized service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Configuring cross-domain calls
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Working cross-domain from a trusted Silverlight application
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Reading XML using HttpWebRequest
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The request
          2. The response
          3. Threading headaches
        4. See also
      7. Reading out an RSS feed
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. RSS versions
      8. Accessing a database in the cloud
        1. Getting ready
        2. How to do it...
        3. How it works
      9. Accessing a service in the cloud
        1. Getting ready
        2. How to do it...
        3. How it works
        4. See also
      10. Running a Silverlight application from the cloud
        1. Getting ready
        2. How to do it...
        3. How it works
          1. There's more
        4. See also
      11. Using socket communication in Silverlight
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The policy server
          2. The socket server
          3. Connecting the Silverlight application
    15. 8. Talking to WCF and ASMX Services
      1. Introduction
      2. Invoking a service that exposes data
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The WCF service
            1. Connecting to the service
        4. See also
      3. Invoking a service such as Bing.com
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
          3. See also
      4. Optimizing performance using binary XML
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The default configuration is different depending on the version of Silverlight you're using
          2. Using binary encoding is not a security measure
        4. See also
      5. Debugging a service in Silverlight
        1. Getting ready
        2. How to do it...
          1. How it works...
            1. Types of faults
              1. Declared faults
              2. Undeclared faults
      6. Using ASP.NET Authentication in Silverlight
        1. Getting ready
        2. How to do it...
          1. How it works...
            1. There's more
      7. Uploading files to a WCF service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Displaying images as a stream from a WCF service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    16. 9. Talking to WCF and ASMX Services—One Step Beyond
      1. Introduction
      2. Using duplex communication over HTTP
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. PollingDuplexBinding: polling, binding, and assemblies
          2. The service
          3. The client
        4. See also
      3. Using duplex communication with the WCF net.tcp binding
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Running with elevated permissions
          2. Setup requirements
        4. See also
      4. Ensuring data is encrypted
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Securing service communication using message-based security
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Transport security is required
        4. See also
      6. Integrating Windows Identity Foundation in Silverlight
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Calling a WCF service from Silverlight using ChannelFactory
        1. Getting ready
        2. How to do it...
        3. How it works...
    17. 10. Talking to REST and WCF Data Services
      1. Introduction
      2. Reading data from a REST service
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. See also
      3. Parsing REST results with LINQ To XML
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Persisting data using a REST service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      5. Working with the ClientHttp stack
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Advantages of the ClientHttp stack
        4. See also
      6. Communicating with a REST service using JSON
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      7. Using WCF Data Services with Silverlight
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Locked-down services
        4. See also
      8. Reading data using WCF Data Services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      9. Persisting data using WCF Data Services
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. There's more...
      10. Talking to Flickr
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Flickr... more information
        5. See also
      11. Talking to Twitter over REST
        1. Getting ready
        2. How to do it...
          1. How it works...
          2. See also
      12. Passing credentials and cross-domain access to Twitter from a trusted Silverlight application
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Let's go cross-domain!
          2. Pass me those credentials, will you?
        4. See also
    18. 11. Using WCF RIA Services
      1. Introduction
      2. Setting up a data solution to work with WCF RIA Services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. The WCF RIA Services Toolkit
        5. See also
      3. Using a WCF RIA Services class library
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. What about the WCF RIA Services link in the Silverlight client?
          2. Better naming, no templates
        5. See also
      4. Getting data on the client
        1. Getting ready
        2. How to do it...
        3. How it works..
        4. There's more...
          1. Some details on code generation
          2. Aren't there some properties missing?
          3. Excluding some properties
        5. See also
      5. Using LoadBehavior to control what happens to your data once it's sent to the client
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Controlling the server-side query from the client
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Sorting and filtering data on the server
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Paging through your data
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      9. Persisting a change set/unit of work
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      10. Working with concurrency and transactions
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
    19. 12. Advanced WCF RIA Services
      1. Introduction
      2. Tracking a user's identity default Windows authentication
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      3. Tracking a user's identity — a custom authentication service
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      4. Integrating Windows Identity Foundation with WCF RIA Services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      5. Controlling a user's access to services and service methods
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      6. Validating data: using data annotations
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      7. Validating data: writing a custom validator
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      8. Validating data: server-side validation with client-side feedback
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      9. Validating data: triggering validation when needed
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      10. Validating data: using the ValidationContext
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Why is my Validation.Items collection sometimes empty?
        5. See also
      11. Handling errors on the server
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      12. Using SQL Azure with WCF RIA Services
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
      13. Exposing WCF RIA Domain Services as OData endpoints
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      14. Exposing WCF RIA Domain Services for other technologies
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
        5. See also
    20. 13. Windows Phone 7
      1. Introduction
        1. The sample scenario for this chapter
      2. Getting our environment ready to start building Windows Phone 7 applications
        1. How to do it...
      3. Building your first data-driven Windows Phone 7 application
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Application model, a device, and the emulator
          2. Pages, navigation, and orientation
          3. Application Bar
          4. Isolated Storage
          5. Panorama and Pivot
        4. See also
      4. Getting data on your Windows phone 7 using WCF
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. ASMX services
          2. WCF services
          3. Data transfer
          4. Credentials
          5. What works and what doesn't work
        4. See also
      5. Accessing REST services from Windows Phone 7 using XML
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Accessing REST services from Windows Phone 7 using JSON
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Why JSON?
        4. See also
      7. Working with push notifications using the cloud
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      8. Storing data in a local SQL CE database
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. The database context
          2. The model classes
          3. Interaction with the database
          4. Save often
        4. See also
      9. Using the background transfer service
        1. Getting ready
        2. How to do it...
        3. How it works...
          1. Restrictions
    21. A. Appendix
      1. Creating a REST service from WCF
      2. Installing an SQL Server database
        1. Attaching an MDF file
        2. Executing a query file
      3. Working with Fiddler
        1. Local traffic
      4. Working with the Silverlight control toolkit
      5. Working with WIF
      6. Installing the WCF RIA Services Toolkit
      7. Installing and using NuGet
    22. Index