简体   繁体   中英

Set a time limit on a response from a web service

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.

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM