HttpWebRequest

Besides WebClient, the HttpWebRequest class is another option that allows web service requests to be made. WebClient offers a simple yet effective API to invoke and consume web services from Silverlight applications. All calls made through WebClient are actually passed through the HttpWebRequest class under the covers. WebClient is basically a simplified wrapper on top of HttpWebRequest. You should use the HttpWebRequest class when you require more granular control over the web service call.

HttpWebRequest exposes properties that allow customization of the web service call by including headers through the Headers property and setting the content type through the ContentType property. Table 7-2 lists some of the most important members of HttpWebRequest used in invoking web services.

Table 7-2. Key methods and properties of HttpWebRequest

Methods and events

Type

Description

Abort

Method

Cancels a request made with HttpWebRequest.

BeginGetRequestStream

Method

Begins the asynchronous request for a stream to send HTTP request data to a service.

BeginGetResponseStream

Method

Begins the asynchronous request for a stream to receive an HTTP response from a service.

Create

Method

Method of the base class WebRequest. It creates an instance of a WebRequest given a URI.

EndGetRequestStream

Method

Ends the asynchronous request to obtain a stream to send an HTTP request.

EndGetResponse

Method

Ends the asynchronous request to obtain a stream to receive an HTTP response.

ContentType

Property

Gets or sets the ...

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.