October 17, 2018
Hot Topics:

RESTing with the Microsoft REST Starter Kit

  • June 22, 2009
  • By Jeffrey Juday
  • Send Email »
  • More Articles »


One other interesting feature of the HttpClient is the HttpStage Collection. HttpStage collection acts as a sort of pipeline for the HttpClient allowing things like caching data or performing additional operations on the HttpRequestMesage or HttpResponseMessage. Below is the StageProcessingTest class implementation.

  class StageProcessingTest : HttpProcessingStage
      public override void ProcessRequest(HttpRequestMessage request)
          Console.WriteLine("Request stage executed...");
      public override void ProcessResponse(HttpResponseMessage response)
          SampleResponseBody respBody = null;
          respBody = response.Content.ReadAsDataContract<SAMPLERESPONSEBODY>();
          Console.WriteLine( "Response stage executed... " + respBody.Value + " added something");

HttpProcessingStage, the base class for StageProcessingTest, is a specialized implementation of HttpStage.

Async Programming Model

Below is the same Post performed above, but this time using the Asynchronous Programming Model.

      request.Data = "My request asnyc...";
      HttpContent content = HttpContentExtensions.CreateDataContract(request);
      Uri doWork = new Uri("DoWork", UriKind.Relative);
      HttpRequestMessage reqMessage = new HttpRequestMessage("POST", doWork, content);
      http.SendCompleted += AsnycSendComplete;
  static void AsnycSendComplete(object sender, SendCompletedEventArgs eSendCompletedEventArgs)
      SampleResponseBody respBody = null;
      respBody = eSendCompletedEventArgs.Response.Content.ReadAsDataContract();
      Console.WriteLine("AsnycSendComplete " + respBody.Value);

In the Async invocation the developer creates the HttpRequestMessage, supplies a delegate callback function, in the example "AsyncSendComplete", and then calls SendAsync. Like the synchronous functions a single class, in this case the SendCompletedEventArgs, returns the Content and the status of the invocation.


REST has become a fixture in the Microsoft product line. First becoming part of WCF, then part of some strategic products, and finally settling in the Microsoft REST Starter Kit. An intuitive set of classes shipping with the Starter Kit, make REST construction accessible to any .NET developer.


Projet Source Code
.NET Framework Conceptual Overview
HttpClient in REST starter Kit Preview 2
REST in Windows Communication Foundation
Introduction to the HttpClient

Page 3 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date