What happend to generic HttpResponseMessage<T> ?

Topics: ASP.NET Web API
May 9, 2012 at 9:34 PM

I recently pullled the night webapi build ('AspNetWebApi 4.0.20509.0) and it appears that the the generic HttpResponseMessage has been removed.

The old syntax was something like :

 > HttpResponseMessageExcepton <MyFancyObject>(my_fancy_object);


Whats the new syntax?  How do you stuff your object into a response message for later formatting?



May 9, 2012 at 11:24 PM
Edited May 9, 2012 at 11:30 PM

Best way I found is an extension method for HttpRequestMessage: HttpRequestMessageExtensions.CreateResponse<T>(), e.g.

using System.Net.Http;

HttpResponseMessage response = controllerContext.Request.CreateResponse(HttpStatusCode.Created, MyData);

Another thread in here describes why the generic HttpResponseMessage was removed.  Basically it wasn't type safe in that Content could later be accessed but not guaranteed to be of type T.

May 12, 2012 at 11:25 AM


Thanks for the heads up, this is exactly what I needed.