Creating an ASMX Web Service
Generally, developers will either communicate with an existing web service or create a web service for their own purposes. This chapter will demonstrate a few variations of web services and how you can communicate with them from Silverlight 2 clients. First, we’ll examine what you need in order to create an ASMX web service and communicate with it from a Silverlight 2 client application.
The example Silverlight 2 application we’ll create will allow a
user to send an email message. Because the Silverlight client does not
have access to the System.Net.Mail
namespace, it must communicate with a server that allows it to send
email messages. Otherwise, the
client could invoke the default mail application and use it to send a
message. However, a server-based solution is often more advantageous, as
it allows for far more customization.
The Silverlight 2 application shown in Figure 5-2 simply allows the user to enter the basic information for sending an email message. When the user enters the information for the email message and clicks the Send via ASMX button, the Silverlight application creates a proxy to the ASMX web service, adds an event handler to handle the return of the ASMX web service call, and invokes the web service asynchronously. The web service is passed the information from the Silverlight client application, which the service then uses to send the email to the recipient(s).
Figure 5-2. Silverlight email client
Getting Started with the Example
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.