Reputation: 1762
If I call a web service ...
Service1 myWebService = new Service1();
int NewTotal = myWebService.CurrentBreakdowns(6);
How can I set a time limit on getting a response from the web service. I want to give it 30 seconds to respond and, if a response is not received, carry on and show a 'did not receive a timely response' message.
Upvotes: 4
Views: 7017
Reputation: 51
Hi bro I gave a time limit on client with this code;
firstly create service proxy in class
private BussinessAdapter serviceProxy = null;
in constructer assign a new adapter with this:
serviceProxy = new BussinessAdapter();
And you can set the time with this code in functions;
serviceProxy.Timeout=3000000; //to 50 min I gave
... and you need to sync with web service time out time my web service has the same time limit.
Upvotes: 0
Reputation: 3571
You can set the timeout as follows
localhost.Service1 service = new localhost.Service1();
service.Timeout = 30000;
where Timeout Indicates the time an XML Web service client waits for the reply to a synchronous XML Web service request to arrive (in milliseconds).
You can also try as suggested in the following post in SO
Upvotes: 1
Reputation: 48726
Try adding this line under your <system.web>
in your web.config:
<httpRuntime executionTimeout="30"/>
Wrap your service call in a try/catch
block and handle the exception.
Upvotes: 0