How to return properly formatted responses from message handlers?

Topics: Web Api
Feb 2, 2012 at 10:36 PM
Edited Feb 2, 2012 at 10:38 PM

I'm flipping out over this.

How can you get this super simple piece of code to actually return the formatted content that it should?

 


    public class MessageHandler : DelegatingHandler    {       

protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)        {


            return Task.Factory.StartNew<HttpResponseMessage>(() =>            { 

              var msg = new ErrorMsg();               

msg.Something = "x";               

r.Content = new StringContent(new ObjectContent(msg.GetType(), msg).ReadAsStringAsync().Result);               

return x.Result;           

}

         }

     }
    public class ErrorMsg    {       

public string Something { get; set; }   

}

Feb 2, 2012 at 10:36 PM
Edited Feb 2, 2012 at 10:41 PM

I don't know why but the WYSIWYG formatter won't let me post code in chrome.

... and I get an error visiting codeplex on firefox.