Try - Catch

  • Thread starter Thread starter Rudiga
  • Start date Start date
R

Rudiga

Hi

I am trying to build in a try-catch block to access a web service and am
trying to control how long it attempts to access to service before running
the catch part of the code. Is there a specific way of doing this?

try

{

// access service

//ans = return answer from service

//run calculations on answer

}

catch (Exception)

{

Console.WriteLine("Error in connecting to service");

}

This code works however takes forever to give up the try part of the code.

Thank you

Rudiga
 
You need to change the timeout for the service. This depends on what sort
of service you are accessing. Is it a WebService? TCP/IP?
 
Its a webservice


Arran Pearce said:
You need to change the timeout for the service. This depends on what sort
of service you are accessing. Is it a WebService? TCP/IP?
 
If you are using a webrequest, you can set the timeout of the webrequest. An
exception will be thrown if the timeout has been exceeded.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 
I am using a web service, i.e. Projects>>Add Web Reference. I havent found
any type of timeout for the request. Should it be a line of code or
something in a properties window.



Alvin Bruney - ASP.NET MVP said:
If you are using a webrequest, you can set the timeout of the webrequest.
An
exception will be thrown if the timeout has been exceeded.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



Rudiga said:
Its a webservice
 
Rudiga said:
I am using a web service, i.e. Projects>>Add Web Reference. I havent found
any type of timeout for the request. Should it be a line of code or
something in a properties window.

That creates a proxy class that inherits from SoapHttpClientProtocol. That
proxy class has the methods defined on it that you use when calling our
webmethods. It also has Timeout property. After you have created your
local instance of the proxy class, set the Timeout value to however long you
are willing to wait, then call the web method.
 
Back
Top