Try - Catch

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
 
A

Arran Pearce

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?
 
R

Rudiga

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?
 
A

Alvin Bruney - ASP.NET MVP

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
 
R

Rudiga

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
 
T

Tom Porterfield

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top