What if a webservice is not available = "execution expired"


#1

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","http://www.webserviceX.NET/”)
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_amtrate)
when “GBP”
sprintf(“£%0.2f”, can_amt
rate)
when “EUR”
sprintf("?%0.2f", can_amtrate)
when “AUD”
sprintf("$%0.2f AUS", can_amt
rate)
when “MXN”
sprintf("%0.2f Mx Pesos", can_amt*rate)
end
end


#2

Resolved. I found Timeout.

Thanks,
Peter