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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:21:28+00:00 2026-06-10T14:21:28+00:00

I have a WP7 app where I’m trying to reconstruct an HTTPWebRequest that I

  • 0

I have a WP7 app where I’m trying to reconstruct an HTTPWebRequest that I have successfully written elsewhere using the synchronous methods (pasted at end) but which doesn’t work in WP7, I assume because I’m doing something wrong with the Asynchronous versions of these methods.

I believe the issue stems from the fact that the non-working code on the Compact Framework can only send a bytearray[] – I don’t have the option of sending the json string. If I send a bytearray in the code that works, I get an error there too. Is there a different option?

Here is my code – this does not work. The exception is thrown on the 2nd line of the last method – “Using(var respons …)”:

public void CreateUser()
    {
        var request = (HttpWebRequest)WebRequest.Create("http://staging.cloudapp.net:8080/api/users/");
        request.Method = "POST";
        request.ContentType = "text/json; charset=utf-8";
        request.BeginGetRequestStream(new AsyncCallback(RequestCallback), request);
    }

    private static void RequestCallback(IAsyncResult result)
    {
        HttpWebRequest request = (HttpWebRequest)result.AsyncState;

        using (Stream postStream = request.EndGetRequestStream(result))
        {
            User user = new User("Windows", "Phone", "USCA");

            Formatting formatting = new Formatting();
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            string json = JsonConvert.SerializeObject(user, formatting, settings);

            byte[] byteArray = Encoding.UTF8.GetBytes(json);

            postStream.Write(byteArray, 0, json.Length);
        }

        request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
    }

    private static void ResponseCallback(IAsyncResult result)
    {
        var request = (HttpWebRequest)result.AsyncState;
        using (var response = (HttpWebResponse)request.EndGetResponse(result))
        {

            using (Stream streamResponse = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(streamResponse);
                string responseString = reader.ReadToEnd();
                reader.Close();
            }
        }
    }

This code works (non-compact framework version of the same request):

HttpWebRequest request = HttpWebRequest.Create("http://staging.cloudapp.net/api/users/") as HttpWebRequest;
        request.Method = "POST";
        request.ContentType = "text/json";
        using (var writer = new StreamWriter(request.GetRequestStream()))
        {
            User user = new user("Other", "Guy", "USWC");
            Formatting formatting = new Formatting();
            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            string json = JsonConvert.SerializeObject(user, formatting, settings);

            writer.Write(json);
        }

        var response = request.GetResponse() as HttpWebResponse;
        using (var reader = new StreamReader(response.GetResponseStream()))
        {
            var responseText = reader.ReadToEnd();
            return responseText;
        }

thanks for any help!

  • 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-10T14:21:30+00:00Added an answer on June 10, 2026 at 2:21 pm

    Well – I’m not sure why this problem went away. I liked @RowlandShaw’s suggestion, but I didn’t actually change anything in the json. Wish I could give a better solution.

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

Sidebar

Related Questions

I have a WP7 app that is connecting to my GAE backend via oauth.
Just trying to write my first ever WP7 app. I have several hundreds of
I have a WP7 app (Silverlight) that has a page with a textbox that
i have a problem with a WP7 app. I want that a user can
I have just started trying to build my first wp7 app, and I am
I have a Mango WP7.5 app that uses a local SqlCe database. I would
I have been trying to use some custom fonts within my WP7 app. I
I am trying to make a WP7 app that would Tweet short messages user
I'm using reactive extensions in my wp7 app that I'm making and I wish
I have a WP7 app that requires most of its pages to retrieve data

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.