Frage

What is the equivalent of

var newOrder = new OrderViewModel()
{

   Id = orderDetails.Id,
   Name = orderDetails.Service.Name,
   .....
};

Request.CreateResponse(HttpStatusCode.OK, newOrder);

In this format:

HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
response.ReasonPhrase = "successfully created blablabla";

In the Request.CreateResponse() I can pass an object. How can I do that with HttpResponseMessage?

Want to be able to pass a message (like ReasonPhrase) as well, but can't do that with Request.CreateResponse(). Or I'm missing something.

War es hilfreich?

Lösung

To pass in an object as response content you can construct ObjectContent<T>:

response.Content = new ObjectContent<OrderViewModel>(newOrder, 
                                         new JsonMediaTypeFormatter())

Other constructors of ObjectContent:

http://msdn.microsoft.com/en-us/library/hh835040(v=vs.118).aspx

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top