Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:16:34+00:00 2026-06-11T20:16:34+00:00

In one of my Get request, I want to return an HttpResponseMessage with some

  • 0

In one of my Get request, I want to return an HttpResponseMessage with some content. Currently I have it working as follows:

var header = new MediaTypeHeaderValue("text/xml");
Request.CreateResponse(HttpStatusCode.OK, myObject, header);

However, since I am using the static Request, this becomes really difficult to test. From what I have read, I should be able to do the following:

return new HttpResponseMessage<T>(objectInstance);

However, seem to not be able to do this. Is it because I am using a older version of WebApi / .NET?


On a side note, I found that you could potentially create a response as follows:

var response = new HttpResponseMessage();
response.Content = new ObjectContent(typeof(T), objectInstance, mediaTypeFormatter);

What puzzled me is why do I have to add a mediaTypeFormatter here. I have added the media type formatter at the global.asax level.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:16:35+00:00Added an answer on June 11, 2026 at 8:16 pm

    HttpResponseMessage<T> was removed after Beta. Right now, instead of a typed HttpResponseMessage we have a typed ObjectContent

    If you manually create HttpResponseMessage using its default parameterless constructor, there is no request context available to perform content negotiation – that’s why you need to specify the formatter, or perform content negotiation by hand.

    I understand you don’t want to do that – so use this instead:

    HttpResponseMessage response = Request.CreateResponse<MyObject>(HttpStatusCode.OK, objInstance);
    

    That would create the response message relying on the content negotiation performed against the request.

    Finally, you can read more about content negotiation here On this link

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST service that gets a GET request, and I want it
Each request in my web app can get one data access object instance (of
One possible solution could be simple HTTP get or post request, but that wouldn't
I want to get one record before start date and end date DtpFrom means
I need to get one page (can be cURL, or filegetcontent), get some info
I have an app that makes a HTTP GET request to a particular URL
I've got some links I want to have dynamically open in a jQuery UI
I have a seach by name function, which should return the name of one
I have the following code which takes a normal HTTP GET Request and returns
I have a REST service which takes a JSON request. I want to validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.