# Soap

**URL:** <https://www.ruby-forum.com/t/soap/93440>\
**Category:** Ruby\
**Created:** [April 3, 2006, 10:46am UTC](https://www.ruby-forum.com/t/soap/93440 "2006-04-03T10:46:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [April 3, 2006, 10:46am UTC](https://www.ruby-forum.com/t/soap/93440/1 "2006-04-03T10:46:58Z")

</div>

Hi quick question, I have a soap server and soap client ruby scripts.

When I try to run the soap client without starting up the up the server  
the client program crashes out, as you would expect. But I’d like to  
catch that exception and wait 5 min’s before it tries again.

so I have a little bit of code that goes.  
begin  
Timeout::timeout(900) do #try 3 times before quiting.  
not\_connected = true  
while not\_connected == true do  
begin  
@soap\_wrp =  
SOAP::RPC::Driver.new(“[http://localhost:9001](http://localhost:9001)”, “[http://fasw111/Submit](http://fasw111/Submit)”)  
not\_connected = false  
puts @soap\_wrp  
rescue SystemExit  
not\_connected = true  
sleep 300 #sleep for 5 min  
end  
end  
#do some soap stuff

```
    rescue Timeout::Error
     puts "time out error"
     soap_wrp = -1
  end

```

But once the SOAP::RPC::Driver.new fails to find the server there seems  
to be a complete crashs out of the code.  
Does anyone know how I can get around this?

Thanks.  
fishman2001.

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [April 4, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/soap/93440/2 "2006-04-04T16:15:44Z")

</div>

On 2006-04-03 01:47:03 -0700, fish man [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> Hi quick question, I have a soap server and soap client ruby scripts.
> 
> When I try to run the soap client without starting up the up the server  
> the client program crashes out, as you would expect. But I’d like to  
> catch that exception and wait 5 min’s before it tries again.

A couple of thoughts that are non-specific to the SOAP modules:

Try rescuing on Exception instead of SystemExit… If that fixed your  
troubles, then you know you’re catching the wrong exception. Another  
important thing to do (obviously) is read the information on whatever  
is terminating execution.

Aside, your timeout is not going to ensure trying 3 times. It will wait  
900 seconds, but depending on how long the connection takes to timeout,  
your 300 second sleep will cause more troubles.

What might be better is something like this:

3.times do  
begin  
@soap\_wrp = SOAP::Stuff # fill in your driver here  
rescue Exception =\> e  
puts e # for debugging  
end  
end

exit(-1) unless @soap\_wrp # @soap\_wrp is nil, we are not connected

# rest of code…

This may look just like a shorter solution, but it solves a lot of  
potential problems due to eliminating unnecessary complexity.

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [April 4, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/soap/93440/3 "2006-04-04T16:31:10Z")

</div>

On 2006-04-04 07:12:04 -0700, Erik H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> 3.times do  
> begin  
> @soap\_wrp = SOAP::Stuff # fill in your driver here  
> rescue Exception =\> e  
> puts e # for debugging  
> end

There should be a ‘break if @soap\_wrp’ right here.

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [April 4, 2006, 6:04pm UTC](https://www.ruby-forum.com/t/soap/93440/4 "2006-04-04T18:04:33Z")

</div>

Erik H. wrote:

> On 2006-04-04 07:12:04 -0700, Erik H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:
> 
> > 3.times do  
> > begin  
> > @soap\_wrp = SOAP::Stuff # fill in your driver here  
> > rescue Exception =\> e  
> > puts e # for debugging  
> > end
> 
> There should be a ‘break if @soap\_wrp’ right here.

I did this, tried to catch the exception, but it still crashes out.  
give the error  
Errno::ECONNREFUSED

any ideas?

---

<div class="post-metadata">

**Author:** ![fishman2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/e9bcb4/32.png) [@fishman2001](https://www.ruby-forum.com/u/fishman2001)\
**Post date:** [May 14, 2007, 9:29pm UTC](https://www.ruby-forum.com/t/soap/93440/5 "2007-05-14T21:29:01Z")

</div>

I know this is a VERY stale thread, but would this Exception actually  
catch a Timeout? I ask because I need to do this so our app doesn’t get  
hung up if the webservice we are calling tips over. Perhaps (likely)  
there is something obvious I have just not seen, but it seems like this  
should be fairly trivial to do.

-jay
