WCF Web API–HTTP Message classes

This is the fifth post on a series about the new Preview 4 of WCF Web API. The previous posts were:

In this post, I briefly present the HTTP message classes, which are at the core of the WCF Web API processing model.

The following diagram shows the main classes for representing both requests and responses.HttpMessages

  • The two main classes are HttpRequestMessage, representing a HTTP request; and HttpResponseMessage, representing a HTTP response.
  • Both HttpRequestMessage and HttpResponseMessage have a Content property, of type HttpContent (abstract class) that represents the message’s body. Some available concrete content classes are
    • ByteArrayContent;
    • StringContent;
    • FormUrlEncodedContent;
    • StreamContent.
  • There are three different classes for message header representation
  • These classes are composed by a set of properties, one for each represented header. This allow for an easier access to headers (e.g. someRequest.Headers.Accept).
  • Note that the entity-headers are referenced by the content class and not directly by the request or response classes.
  • Note also that both the request’s Method and the response’s StatusCode are classes/enums and not just strings or integers.
  • Both HttpRequestMessage and HttpResponseMessage are concrete classes with public constructors, allowing for their simple instantiation, namely in testing scenarios.
  • Despite their core role in the HTTP Web API, these message classes belong to a different assembly – Microsoft.Net.Http.

2 thoughts on “WCF Web API–HTTP Message classes

  1. Pingback: HTTP content classes « Pedro Félix’s shared memory

  2. Pingback: WCF Web API–Description Model « Pedro Félix’s shared memory

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s