Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning a HttpWebResponse ASP.Net MVC
    text
    copied!<p>I'm using a .Net MVC application as a simplified web service.</p> <p>I've got an async method that I call:</p> <pre><code>public void RunQueue() { QueueDelegate queue = new QueueDelegate(Queue); AsyncCallback completedCallback = new AsyncCallback(QueueCompleteCallback); lock (_sync) { if (!queueIsRunning) { AsyncOperation async = AsyncOperationManager.CreateOperation(null); queue.BeginInvoke(QueueCompleteCallback, async); queueIsRunning = true; } } } </code></pre> <p>and the hope is that when I call it, it starts the queue and then lets the user continue on with their day (they'll get an email when the queue's done).</p> <p>As it stands right now, everything works fine except that instead of letting the user continue on, the webpage calling the "web service" just hangs and the request eventually times out.</p> <p>How do I build an HttpWebResponse and send it back to the other server so that the user can continue on?</p> <p>I've tried having it return things other than "void" but that doesn't do much.</p> <p>Here's the Controller that's calling it.</p> <pre><code>public ActionResult StartQueue() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:2394/Home/RunQueue/"); HttpWebResponse response; string r = ""; try { response = (HttpWebResponse)request.GetResponse(); Stream stream = response.GetResponseStream(); StreamReader reader = new StreamReader(stream); r = reader.ReadToEnd(); } catch (WebException ex) // A WebException is not fatal. Record the status code. { response = (HttpWebResponse)ex.Response; if (response != null) // timeout { r = response.StatusCode.ToString(); } } ViewData["message"] = r; return View(); } </code></pre>
 

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