If you're used to writing applications that communicate directly with a database (such as SQL Server), you might be surprised to find that there is no object in Silverlight to enable you to do so (SqlConnection
, OdbcConnection
, etc.). This is because Silverlight is a client platform, designed to be run from within a browser anywhere in the world, and so it does not make sense for it to be able to access databases
directly because databases are generally hidden behind a firewall. The purpose of a service is to provide an interface for exposing data publicly from the server, acting as a conduit between the data in the database and external applications.
In addition to exposing data from the server, services also enable you to do the following:
.NET applications typically use Windows Communication Foundation (WCF) Services to implement these services. WCF RIA Services is a layer on top of WCF, providing enhanced functionality and structure for consuming data in your Silverlight applications. Although this chapter will primarily focus on RIA Services, it's worth taking a look at its underlying WCF foundation first. Before we do that, we need a source of data to expose from the server, so let's set up a database and make it available to our AdventureWorks.Web
project.