Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding workaround for HttpWebRequest timeout issue
    primarykey
    data
    text
    <p>I'm using the HTTP Web Request class to call a RESTful web service. I need to pass data and receive data and it all seems to work very well. Today I attempted to configure the time-out of the class because there is a high likelihood of the server running the service being offline and I don't want to waste time waiting. I configured it all but it seemed to make no difference. The call still waited over 10 seconds before failing. </p> <p>On looking into it I found that the time-out only deals with the processing of the call and that the DNS lookup beforehand is not included. As this would be the problem it would make sense as to why the time-out wasn't working as I'd expected.</p> <p>Further reading suggested using the HttpWebRequest class in an asynchronous style instead. I've had a look at the code to do so but don't understand how to retrieve the callback in my code which is effectively synchronous. </p> <p>The code I have as follows is as so:</p> <pre><code>HttpWebRequest _serviceRequest = (HttpWebRequest)WebRequest.Create(new Uri("http://mywebservice.com")); _serviceRequest.Timeout = 3000; HttpWebResponse response = (HttpWebResponse)_serviceRequest.GetResponse(); XmlReader reader = XmlReader.Create(response.GetResponseStream(), set); </code></pre> <p>The code I have to call asynchronously ends with the following line, but I'm not sure as to what I should do to get the response object. </p> <pre><code>IAsyncResult result = (IAsyncResult)req.BeginGetResponse(new AsyncCallback(RespCallback), reqState); </code></pre> <p>I'm also concerned about a half baked asynchronous solution such as this. Is it good practice to use an asynchronous method through a synchronous piece of code.</p> <p>Any helpers appreciated...</p>
    singulars
    1. This table or related slice is empty.
    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.
    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