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 7862197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:02:14+00:00 2026-06-02T23:02:14+00:00

I have been playing with ASP.NET Web API. I am looking to see can

  • 0

I have been playing with ASP.NET Web API. I am looking to see can I post to a method I have built which simply returns back the object I have POSTED:

On The Accounts Controller:

// POST /api/accounts
public Account Post(Account account)
{
   return account;

}

Code Used To Post:

    public void PostAccount()
    {
        // http://local_ip/api/accounts
        var uri = string.Format("{0}", webServiceRoot); 


        var acc = new Account();
        acc.AccountID = "8";
        acc.AccountName = "Mitchel Cars";
        acc.AccountNumber = "600123801";
        acc.SubscriptionKey = "2535-8254-8568-1192";
        acc.ValidUntil = DateTime.Now;


        var request = (HttpWebRequest)WebRequest.Create(uri);
        request.Method = "POST";
        request.ContentType = "application/xml";
        request.ContentLength = 800;

        XmlSerializer xmlSerializer = new XmlSerializer(typeof(Account));
        xmlSerializer.Serialize(request.GetRequestStream(), acc);

        var response = (HttpWebResponse)request.GetResponse();

        XmlSerializer serializer = new XmlSerializer(typeof(Account));

        var newAcc = (Account)serializer.Deserialize(response.GetResponseStream());

    }

I have removed any error checking or any boiler plate code to make it easier to read. This is strictly a spike just to under stand to to actually POST. My understanding is that you should write to the GetRequestStream(). All the reading and such seems to work ok but I never here back from the request.GetResponse();

If I do a simple get it works fine. I did see you can use a class called HTTPClient for doing this stuff but I can’t use it as I need to get this working for WinForms, Silverlight and Windows Phone all based on .Net 3.5

Any help pushing POCO’s to the server would be a great help, cheers!

ADDITIONAL INFO:

  • Currently I get no error, the test app just hangs.
  • If I turn off the WebAPI project I get a server not found response.
  • I have not changed any routes or any of that.
  • Gets to the same controller work.
  • 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-02T23:02:16+00:00Added an answer on June 2, 2026 at 11:02 pm

    You will need to close the response stream. Most examples I see also show setting the content length. You may be better to serialize to a memory stream and then use the length of that stream as the Content-Length. Unfortunately in .net 3.5 there is no CopyStream so you may have to write that yourself.

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

Sidebar

Related Questions

I have been playing around with the XamlAsyncController , which is based on ASP.NET
I have been playing around with the EF to see what it can handle.
I've been playing around with asp.net MVC3 a bit and have been struggling to
I've been playing with ASP.NET MVC and ran into something I can't figure out.
Hopefully someone can help, I've been playing with ASP.NET MVC 2 for a learning
I have been playing with the Ruby library shoes. Basically you can write a
I'm learning ASP.net and I've been playing around with themes and master pages. I
I am a brand new Java developer (I have been working in asp.net) and
I've been trying to add the ASP.NET toolkit to my web application and I
I am playing with Castle activeRecord, and I have succesfully made an asp.net MVC

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.