Note that there are some explanatory texts on larger screens.

plurals
  1. POHttpClient, multiple async results from single call
    primarykey
    data
    text
    <p>I am stuck and have been banging my head against this problem for a couple of days now and am hoping may be able to help.</p> <p>I am making a call to a http service, which when executed, will kick off a process that will send back multiple status messages. The data comes back as a Json string which is then deserialized into an object.</p> <p>The code I am trying to create already exists as a COM object in a NPAPI browser plugin, however with Google's recent decision to kill such plugins I am forced into looking into a new way to get my data.</p> <p>So far I have made spectacular Swiss cheese of my working code and am able to get the first result back, and that's about it. Here is a snippet of what I have working, the basic premise is that the service is called async and then the results are looped until I get the final status result. Unfortunately, I know this isn't right because I get a connection terminated error when I hit the second iteration.</p> <pre><code>var httpClient = new HttpClient(); await httpClient.GetAsync(url).ContinueWith( (task) =&gt; { do { var response = task.Result; var data = response.Content.ReadAsStringAsync().ContinueWith( (readTask) =&gt; { var data2 = readTask.Result; foo++; }); }while (foo &lt; 5); }); </code></pre> <p>Does anyone have any suggestions? Thanks for the help!</p> <p><strong>Edit</strong></p> <p>Per svick's request here's some more info. As I said the code being executed returns multiple status messages. So I might get a message for 0% done, 5%, 20%, 25%, etc all the way up to 100%. What I am trying to do is trap all of the messages coming back until I get the message saying the status is 100% done.</p> <p>I've also tried using the ReadAsStringAsync method and it only returns the first status message and then closes the connection.</p> <p>Thanks again!</p> <p><strong>Update</strong> Well, it turns out I have been going about this all wrong. Apparently there was a results call built into the service that I could query to get the data I wanted. I guess I missed that part of the architecture meeting.</p> <p>Thanks for everyone that either commented or looked at this!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload