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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:39:20+00:00 2026-06-05T16:39:20+00:00

I believe I’ve set this up correctly. Can somebody see anything wrong with this

  • 0

I believe I’ve set this up correctly. Can somebody see anything wrong with this code. Should it execute IAsyncResult asyncResult1 and then immediate move to IAsyncResult asyncResult2? The behavior is that it invokes asyncResult1 (calling the ExecuteAsyncRequest) the rest service keeps it for a bit and then returns it and the next one is called. Shouldn’t it just BeginGetResponse and then move on to the next call?

The WCF Rest Service web method is:

 public Stream CheckOutForMaster(Stream clientServerXmlStream)
    {
       //Logic 1: Checks if it's between a set 30 second window.
       //Logic 2: Processes more logic
       //Logic 3: Holding pattern until the 30 second window is complete. Thus allowing multiple calls to be made via other connections.
       //Logic 4: Once 30 second window is complete. All connections have saved their  data to a database and each connection will retrieve all data from all connects.
    }

Client side test code:

[TestClass]
public class sccTests
{
    public static ManualResetEvent allDone = new ManualResetEvent(false);
    const int BUFFER_SIZE = 1024;
    const int DefaultTimeout = 2 * 60 * 1000; // 2 minutes timeout
    List<XDocument> asyncClientServers;

    [TestMethod]
    public void CheckoutForMaster_OneClientServer_ReturnsAllMasterStatus()
    {
        string urlTest = CombineWithSccBaseUrl("/v1/clientservers/checkout");
        ...
        IAsyncResult asyncResult1 = ExecuteAsyncRequest(urlTest, xmlPayloadAllMaster);
        IAsyncResult asyncResult2 = ExecuteAsyncRequest(urlTest, xmlPayloadAllWait);
    }

    private IAsyncResult ExecuteAsyncRequest(string url, string payload)
    {
        try
        {

            byte[] bytes = Encoding.UTF8.GetBytes(payload);

            Uri uri = new Uri(url);
            // Create a HttpWebrequest object to the desired URL.
            HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(uri);
            myHttpWebRequest1.Method = "POST";
            myHttpWebRequest1.CachePolicy = new RequestCachePolicy(       RequestCacheLevel.NoCacheNoStore);
            myHttpWebRequest1.ContentLength = bytes.Length;
            myHttpWebRequest1.ContentType = "application/xml;charset=UTF-8";
            myHttpWebRequest1.Timeout = 105000;

            using (Stream putStream = myHttpWebRequest1.GetRequestStream())
            {
                putStream.Write(bytes, 0, bytes.Length);
            }

            // Create an instance of the RequestState and assign the previous myHttpWebRequest1
            // object to it's request field.  
            RequestState myRequestState = new RequestState();
            myRequestState.request = myHttpWebRequest1;

            // Start the asynchronous request.
            IAsyncResult result = myHttpWebRequest1.BeginGetResponse(new AsyncCallback(RespCallback), myRequestState);
        }
        catch (WebException e)
        {
            string t = e.Message;
        }
        catch (Exception e)
        {
            string t = e.Message;
        }

        return null;

    }


    private void RespCallback(IAsyncResult asynchronousResult)
    {
        try
        {
            // State of request is asynchronous.
            RequestState myRequestState = (RequestState)asynchronousResult.AsyncState;
            HttpWebRequest myHttpWebRequest2 = myRequestState.request;
            myRequestState.response = (HttpWebResponse)myHttpWebRequest2.EndGetResponse(asynchronousResult);

            // Read the response into a Stream object.
            Stream responseStream = myRequestState.response.GetResponseStream();
            myRequestState.streamResponse = responseStream;

            if(myRequestState.response != null && myRequestState.response.StatusCode == HttpStatusCode.OK)
            {
                StreamReader reader = new StreamReader(myRequestState.response.GetResponseStream(), Encoding.GetEncoding(1251));
                XDocument xResult = XDocument.Load(reader);
                asyncClientServers.Add(xResult);
            }
        }
        catch (WebException e)
        {
            // Need to handle the exception
        }
    }

 }
  • 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-05T16:39:21+00:00Added an answer on June 5, 2026 at 4:39 pm

    Documentation for GetRequestStream says:

    Your application cannot mix synchronous and asynchronous methods for a particular request. If you call the GetRequestStream method, you must use the GetResponse method to retrieve the response.

    It doesn’t say what happens if you do try to mix synchronous methods, but seeing as you’re getting unexpected results from doing so, you probably want to use BeginGetRequestStream.

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

Sidebar

Related Questions

I believe in JAVA we can set the data reader to point to the
I believe there's a typo on this code snippet extracted from Stroustup's book, at
I believe this is trivial, but I can't for the life of me, figure
I believe I have set up our MVC app to use [HandleError] properly. This
believe me I have tried to code this, tried Google, and haven't had any
I believe this has been answered before but how can I have buttons /
I believe there should exist a known method for converting this: <div class=singlePane pane>
i believe this is a simple question but i can't figure out myself. In
I believe I have a simple question.... but for me as beginner, I can't
I believe this post is the resolution to my trouble Flickering when navigating between

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.