Peter Michaux
2006-Mar-28 04:16 UTC
[Rails] What if a webservice is not available = "execution expired" error
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_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 Michaux
2006-Mar-28 04:46 UTC
[Rails] Re: What if a webservice is not available = "execution expired" error
Resolved. I found Timeout. Thanks, Peter On 3/27/06, Peter Michaux <petermichaux@gmail.com> wrote:> 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_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 >