Share via


Lab 07: Working with WCF Services in Silverlight Applications

Windows Communication Foundation (WCF) provides an excellent framework for exchanging data across network boundaries. It can be used to exchange data using standards-based Web Service specifications such as Simple Object Access Protocol (SOAP), Web Service Description Language (WSDL) and WS-I* standards. Any development framework capable of supporting Web Service standards can be used to call a WCF service including non-.NET frameworks.

To create a WCF service you define the ABCs for the service including the Address, Binding and Contract. The Address defines the URI of the service that a client uses to talk with it. You can think of it as being similar to a phone number or street address. The Binding defines the protocol to use while talking with the service. WCF supports several different protocols such as HTTP, TCP, named pipes and more. Finally, the contract defines the service's Application Programming Interface (API) including the data it can send and receive. The contract includes service operation names, data types used, as well as additional details.

WCF is a key player in Silverlight applications that need to access and manipulate data. Although standard WCF service projects can be created a used with Silverlight, The Silverlight Tools for Visual Studio 2010 provides a Silverlight-Enabled WCF Service project template that can be used to create service classes. The template configures services to use binary message encoding combined with the HTTP protocol which provides excellent performance. A WCF service can be called directly from a Silverlight application using a proxy object that is typically created directly in Visual Studio.

In this lab you'll learn how to create a Silverlight-Enabled WCF Service and define operations. You'll also examine the default configuration for Silverlight-enabled services and create a proxy object that can be used to communicate with a service from a Silverlight client. A bonus exercise is also included that demonstrates how to debug WCF service calls using a tool called Fiddler. The user interface that you'll build throughout the lab is shown next:

Figure 1

User Interface Example

You Will Benefit from this Lab if:

  • You need to integrate distributed data into a Silverlight application
  • You're interested in learning more about Windows Communication Foundation fundamentals
  • You're interested in learning how to extend proxy objects using partial classes

You Will Learn:

  • How to create a Silverlight-Enabled WCF Service
  • How to define service operations
  • Best practices for adding code into service operations
  • How to create a proxy object that can be used to call a WCF service
  • How to make asynchronous calls from a Silverlight client to a WCF service
  • How and why to use the IEditableObject interface

Business Requirements for the Silverlight application include:

  • Create a new Silverlight Navigation Application
  • Create an Entity Framework 4 model
  • Create a Silverlight-Enabled WCF Service
  • Customize service methods
  • Create a Silverlight proxy object in Visual Studio
  • Build a user interface
  • Use a proxy object to call a WCF Service
  • Add IEditableObject functionality to a proxy generated class

Estimated Time: 60 minutes