Creating a Silverlight-Enabled WCF Service

You can modify the sample application shown throughout this chapter to use a WCF web service instead of an ASMX web service. In this section, I will demonstrate a few of the differences in setting up a WCF web service and invoking it from a Silverlight 2 client application.

Creating the WCF Web Service

You can create WCF web services that Silverlight 2 clients can consume either by creating a WCF web service using the default WCF service file template, or by using a Silverlight-enabled WCF Service file template. A standard WCF service file template uses the wsHttpBinding binding. You must change this to basicHttpBinding for Silverlight 2 to be able to communicate with the WCF web service, because Silverlight 2 supports only basicHttpBinding. If a WCF web service is created using the Silverlight-enabled WCF Service file template, basicHttpBinding is set by default.

You can modify the EmailClient application to call a WCF web service. The first step is to create the new WCF web service. The sample code for this chapter contains an IIS web application running under Cassini, named WCFEmailService (an IIS website would also work). You can create a new WCF web service by right-clicking the WCFEmailService project’s node in the Project Explorer, choosing Add New Item, and selecting “Silverlight-enabled WCF Service”. Figure 5-11 shows the WCF web service being named EmailService.svc.

Figure 5-11. Creating EmailService.svc

Bindings

The Silverlight-enabled ...

Get Data-Driven Services with Silverlight 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.