This project is read-only.

What happend to generic HttpResponseMessage<T> ?

Topics: ASP.NET Web API
May 9, 2012 at 10: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 10, 2012 at 12:24 AM
Edited May 10, 2012 at 12:30 AM

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 12:25 PM


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