WebClient
Unlike SOAP services, you cannot create a service reference for a
RESTful web service since most RESTful services do not expose a
contract, nor do they have WSDL definitions. This means a Silverlight 2
client application cannot simply add a service reference to a RESTful
web service. Instead, Silverlight 2 client applications must make use of
the WebClient
and HttpWebRequest
classes to communicate with
RESTful web services.
Note
One of the RESTful tenets is that a resource is self-describing.
An HTTP request using OPTIONS
will
discover what can be done with a resource and the formats supported by
it.
In a nutshell, WebClient
is a
simpler API that can communicate with an HTTP-based web service. It can
send GET
and POST
requests (but not PUT
or DELETE
requests) to a service to send and
receive data. HttpWebRequest
also
provides the means to communicate with HTTP-based web services. It
accepts a URI, just like the WebClient
library, but allows greater
customization of the information sent to the web service, such as more
control over headers than with WebClient
. The WebClient
class uses the HttpWebRequest
class
under the covers, but WebClient
is a
much simpler API and often is all that is required. As with any remote
web service invocation from Silverlight, a cross-domain policy file must
exist on the root of the remote server’s domain to allow Silverlight to
call the service.
Note
Silverlight 2 applications allow communication with remote web services on a domain that is different ...
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.