Forum: Ruby on Rails What if a webservice is not available = "execution expired"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter M. (Guest)
on 2006-03-28 08:16
(Received via mailing list)
Hi,

I'm using a webservice in my application. How can I make it so that my
application will only try to connect to the webservice for a certain
period of time and then give up?

Right now my code is using a begin-rescue-else but sometimes I get a
"execution expired" error if the webservice is not available or takes
too long to respond.

Thanks,
Peter


begin
  service =
SOAP::RPC::Driver.new("http://www.webservicex.net/CurrencyConvertor.asmx"...)
  service.default_encodingstyle =
SOAP::EncodingStyle::ASPDotNetHandler::Namespace
  service.add_method_with_soapaction("ConversionRate",
"http://www.webserviceX.NET/ConversionRate", "FromCurrency",
"ToCurrency")

  rate = service.ConversionRate("CAD",current_currency).to_f
rescue
  sprintf("$%0.2f CAN", can_amt)
 else
  case current_currency
  when "USD"
    sprintf("$%0.2f US", can_amt*rate)
  when "GBP"
    sprintf("£%0.2f", can_amt*rate)
  when "EUR"
    sprintf("?%0.2f", can_amt*rate)
  when "AUD"
    sprintf("$%0.2f AUS", can_amt*rate)
  when "MXN"
    sprintf("%0.2f Mx Pesos", can_amt*rate)
  end
end
Peter M. (Guest)
on 2006-03-28 08:46
(Received via mailing list)
Resolved. I found Timeout.

Thanks,
Peter
This topic is locked and can not be replied to.