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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:25:48+00:00 2026-05-28T08:25:48+00:00

I am running a following code on Windows Phone: string baseAddress = tcAddress +

  • 0

I am running a following code on Windows Phone:

        string baseAddress = tcAddress + "/Api/Audio/RegisterAudioThoughtUpload/";
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(baseAddress);
        request.Method = "POST";
        request.ContentType = "application/json; charset=utf-8";

        int total = 1633;

        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            string json = "{ \"AnonymousUserId\":\"" + Guid.NewGuid().ToString() + "\", \"TotalSize\":\"" + total.ToString() + "\" }";

            streamWriter.Write(json);
            streamWriter.Close();
        }

        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            int statusCode = (int)response.StatusCode; \\At this point response is null
            StreamReader reader = new StreamReader(response.GetResponseStream());
            string results = reader.ReadToEnd();
            response.Close();
        }

Basically I am trying to send a json-packed guid and an int to an mvc3 action.

On the server side, the processing action is:

    [HttpPost]
    public JsonResult RegisterAudioThoughtUpload(string AnonymousUserId, int TotalSize)
    {
        var aUId = Guid.Parse(AnonymousUserId);

        return new JsonResult {Data = Guid.NewGuid()};
    }

A fiddler2, that is logging the communication shows, that the server is providing a client an expected response:

fiddler2

But on the client, a call to GetResponse() just times out, never actually getting a response back.

Since it is Windows Phone, a GetResponse() is implemented the following way:

    private const int DefaultRequestTimeout = 15000;

    public static HttpWebResponse GetResponse(this HttpWebRequest request)
    {
        var dataReady = new AutoResetEvent(false);
        HttpWebResponse response = null;
        var callback = new AsyncCallback(delegate(IAsyncResult asynchronousResult)
        {
            response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            dataReady.Set();
        });

        request.BeginGetResponse(callback, request);

        if (dataReady.WaitOne(DefaultRequestTimeout))
        {
            return response;
        }

        return null;
    }

Why I am not getting an instance of HttpWebResponse, even though I see through proxy, that it is being sent?

  • 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-05-28T08:25:48+00:00Added an answer on May 28, 2026 at 8:25 am

    Since this is a WP application I would recommend you avoid blocking the main UI thread. I’d also recommend you using a JSON serializer instead of manually build JSON strings. So let’s start by defining our models:

    [DataContract]
    public class Request
    {
        [DataMember]
        public string AnonymousUserId { get; set; }
    
        [DataMember]
        public int TotalSize { get; set; }
    }
    

    and then:

    var dataToSend = new Request
    {
        AnonymousUserId = Guid.NewGuid().ToString(),
        TotalSize = 123
    };
    var serializer = new DataContractJsonSerializer(typeof(Request));
    var request = string.Empty;
    using (var stream = new MemoryStream())
    {
        serializer.WriteObject(stream, dataToSend);
        request = Encoding.Default.GetString(stream.ToArray());
    }
    var client = new WebClient();
    client.Headers[HttpRequestHeader.ContentType] = "application/json";
    client.UploadStringCompleted += (sender, e) =>
    {
        // make sure there's no error before trying to access the result
        if (e.Error == null)
        {
            string result = e.Result;
            // TODO: do something with the returned result here
        }
        else
        {
            // some error occurred => notify the UI
        }
    };
    
    client.UploadStringAsync(new Uri(tcAddress + "/Api/Audio/RegisterAudioThoughtUpload), request);
    

    Also another problem I can see in the fiddler Response you have shown from the server is that the Content-Type header was set to application/json and yet the contents is not valid JSON:

    "03cc77ed-e92b-48d9-b471-ba55a6065e2f"
    

    instead of:

    {"Data":"03cc77ed-e92b-48d9-b471-ba55a6065e2f"}
    

    As far as the timeout error is concerned, maybe the response doesn’t get to the phone. Check your network.

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

Sidebar

Related Questions

Running the following code resulting in an HostException; Public Sub RunPowershellInConsole(ByVal scriptText As String)
Running the following code on Windows 7 x64 #include <stdio.h> #include <errno.h> int main()
I'm running the following code (on Windows 7, if it makes a difference): char
I have the following code running in a windows service: WebClient webClient = new
Running the following code, I get a StackOverflowError at the getPackage() line. How can
When running the following code it leaves out one row. When I do a
When running the following code I get no output but I cannot work out
I am running following PHP code to interact with a MS Access database. $odbc_con
I am currently running the following code based on Chapter 12.5 of the Python
I'm running the following code to get a random entry from a dictionary: SELECT

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.