O'Reilly logo

Data-Driven Services with Silverlight 2 by John Papa

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required