473,386 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Try - Catch

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
Mar 6 '06 #1
5 1403
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?
"Rudiga" <no**@none.net> wrote in message
news:Qw*******************@newsfe5-gui.ntli.net...
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

Mar 6 '06 #2
Its a webservice
"Arran Pearce" <ar*********@cellhire.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?
"Rudiga" <no**@none.net> wrote in message
news:Qw*******************@newsfe5-gui.ntli.net...
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


Mar 6 '06 #3
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" <no**@none.net> wrote in message
news:ES*******************@newsfe2-gui.ntli.net...
Its a webservice
"Arran Pearce" <ar*********@cellhire.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?
"Rudiga" <no**@none.net> wrote in message
news:Qw*******************@newsfe5-gui.ntli.net...
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



Mar 6 '06 #4
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" <www.lulu.com/owc> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
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" <no**@none.net> wrote in message
news:ES*******************@newsfe2-gui.ntli.net...
Its a webservice
"Arran Pearce" <ar*********@cellhire.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> 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?
>
>
> "Rudiga" <no**@none.net> wrote in message
> news:Qw*******************@newsfe5-gui.ntli.net...
>> 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
>>
>>
>
>



Mar 6 '06 #5
Rudiga wrote:
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.
--
Tom Porterfield

Mar 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
11
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill...
4
by: Abhishek Srivastava | last post by:
Hello All, I have seen code snippets like try { ..... } catch {
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
13
by: Benny | last post by:
Hi, I have something like this: try { // some code } catch // note - i am catching everything now {
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
23
by: pigeonrandle | last post by:
Hi, Does this bit of code represent complete overkill?! try { //create a treenode TreeNode tn = new TreeNode(); //add it to a treeview tv.Nodes.Add(tn);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.