Book Image

Microsoft Silverlight 4 Data and Services Cookbook

Book Image

Microsoft Silverlight 4 Data and Services Cookbook

Overview of this book

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. Silverlight Data 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 solutions with the platform. Silverlight 3 made a big step into Line-Of-Business data services and Silverlight 4 builds further upon this. This book will enable .NET developers to get their finger on the pulse of data-driven business applications in Silverlight.This book is not a general Silverlight 3/4 overview book; it is uniquely aimed at developers who want to build data-driven applications. 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 covered features work both in Silverlight 3 and 4. However, we cover some that are specific for Silverlight 4, which will therefore not work with Silverlight 3. 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 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. Chapters cover data binding, data controls, the concepts of talking to services, communicating with WCF, ASMX and REST services, and much more.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 upgrading your existing applications to use Silverlight. 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 (16 chapters)
Silverlight 4 Data and Services Cookbook
Credits
About the authors
About the reviewers
Preface

Preface

This practical cookbook 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 3 and 4. However, we cover some that are specific to Silverlight 4, which will therefore not work with Silverlight 3. Where this is the case, it will be 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 services, covering all the options available to access data and communicate with services to make the most out of data in your Silverlight business applications, whilst at the same time providing a rich user experience. Chapters cover data binding, data controls, concepts of talking to services, communicating with WCF, ASMX, and REST services and much more.

By following the practical recipes in this book, which are of varying difficulty levels, you will learn concepts for creating data-rich business applications—from the creation of a Silverlight application, to displaying data in the Silverlight application and upgrading your existing applications to use Silverlight. Each recipe will cover a data services topic, going from the description of the problem, over a conceptual solution and a solution containing sample code.

What this book covers

Chapter 1, Learning the Nuts and Bolts of Silverlight 4 will get you up and running with Silverlight. While this book is aimed at developers who already have a basic knowledge of Silverlight, this chapter can act as a refresher. We'll also look at getting your environment correctly set up so that you enjoy developing Silverlight applications.

Chapter 2, An Introduction to Data Binding will explore how data binding works. We'll start by building a small data-driven application that contains the most important data binding features, to get a grasp of the general concepts. We'll also see that data binding isn't tied to just binding single objects to an interface; binding an entire collection of objects is supported as well. We'll also be looking at the binding modes. They allow us to specify how the data will flow (from source to target, target to source, or both). We'll finish this chapter by looking at the support that Blend 4 provides to build applications that use data binding features. In the next chapter, we'll be looking at the more advanced concepts of data binding.

Chapter 3, Advanced Data Binding teaches you advanced data binding concepts that can be used for customization, validations, and applying templates to data bound controls. We also have a look at converters, that are obvious hooks in data binding and their possibilities.

Chapter 4, The Data Grid covers recipes on how to work with the DataGrid. This is an essential control for applications that rely on (collections of) data.

Chapter 5, The DataForm covers recipes on how to work with the DataForm, which is an essential control for the applications that rely on (collections of) data.

Chapter 6, Talking to Services talks about the rich set of options that Silverlight provides to communicate with services.

Chapter 7, Talking to WCF and ASMX Services discovers Silverlights' built-in support for communicating with Windows Communication Foundation (WCF) and classic ASMX web services. Perform unidirectional as well as bidirectional communication with much better performance using net.tcp binding in WCF using the recipes in this chapter.

Chapter 8, Talking to REST and ADO.NET Data Services takes advantage of REST, which can be significant in the case of Silverlight. We will also look at how we can work with ADO.NET Data Services. You will abstract away a lot of plumbing code with the use of the client-side library that is available for use with Silverlight.

Chapter 9, Talking to WCF RIA Services discovers a new, free framework developed by Microsoft-WCF RIA Services- to simplify Line of Business RIA development. This chapter will teach you to easily design and develop rich data-driven applications by simplifying the access to the validation of and the authentication of services, service methods, and entities.

Chapter 10, Converting Your Existing Applications to Use Silverlight, integrates Silverlight into existing web applications and performs a step-by-step migration where Silverlight starts to become part of a system. This chapter is all about techniques to leverage your existing knowledge, applications, and business requirements to Silverlight. This chapter contains a recipe that shows how to enable WCF RIA Services for existing applications.

Appendix talks about creating a REST service from WCF, installing a SQL Server database, and working with Fiddler and Silverlight control toolkit

What you need for this book

To work with the recipes in this book, it's required that you have Visual Studio installed. This book targets Silverlight 4, which works only with Visual Studio 2010. Many of the recipes in the book will also work in Silverlight 3, so for these recipes, you have the choice of Visual Studio 2008 or 2010. We do recommend using Visual Studio 2010, as it features a lot of enhancements for developing with Silverlight. In both cases, you'll of course need to install the Silverlight Tools, which will update your Visual Studio instance to work with Silverlight. Some recipes also require Blend 4 to be installed on your machine (again, if working with Silverlight 3, Blend 3 will suffice here as well).

The first recipe ofChapter 1, Getting our environment ready to start developing Silverlight applications, explains in detail how to get these tools and how to install them.

Who this book is for

If you are a .NET developer who wants to build professional data-driven applications with Silverlight, then this book is for you. Basic Silverlight experience and familiarity with accessing data using ADO.NET in regular .NET applications is required.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Finally, the DataReader and connection are closed and the StoreDTO object is returned."

A block of code will be set as follows:

<TextBlock x:Name="AmountTextBlock"
Text="{Binding ElementName=AmountSlider, Path=Value}">
</TextBlock>

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in our text like this: "Do this by right-clicking, selecting Add New Item, and then selecting LINQ TO SQL Classes.".

Note

Warnings or important notes appear in a box like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply drop an email to, and mention the book title in the subject of your message.

To send us general feedback, simply drop an email to, and mention the book title in the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or email to.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code for the book

Visit http://www.packtpub.com/files/code/9843_Code.zip to directly download the example code.

The downloadable files contain instructions on how to use them.

Errata

Although we have taken every care to ensure the accuracy of our contents, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in text or code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration, and help us to improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.