Web Service timeout
-
Hello. I'm migrating an application that connects to a remote machine. Before it used sockets, and now a web service. I'm not sure about how to control the time to wait for a response. I'm looking for a kind of timer that waits some time and if it has no response, throws an exception. How can I do that?
Regards, Diego F.
-
Hello. I'm migrating an application that connects to a remote machine. Before it used sockets, and now a web service. I'm not sure about how to control the time to wait for a response. I'm looking for a kind of timer that waits some time and if it has no response, throws an exception. How can I do that?
Regards, Diego F.
You can set the amount of time the webservice will work before sending back an error by setting the executionTimeout attribute in the web.config. Just like you would for a website, like this:
<httpRuntime executionTimeout="180"/>
Then you can put your call to the webservice in a try catch block. The timeout error is a System.Net.WebException. You may want to make sure the message includes the correct error message, though, since there are other System.Net.WebExceptions that could fire. So it would look something like this:Try
myWebService.MyWebServiceMethod(parm1)
Catch ex as System.Net.WebException
If ex.Message.ToUpper.Contains("TIMED OUT") Then
msgbox("Web service method timed out.")
Else
msgbox("Web error: " & ex.Message)
End If
Catch ex as Exception
msgbox("Error: " & ex.Message)
End Try