shreya has asked for the wisdom of the Perl Monks concerning the following question:

I am currently using SOAP::Lite as follows:
my $soap = SOAP::Lite -> uri('https://www.abc.com/') -> proxy('http://abc:9090/SomeClass/ClassName.asmx');
However if the connection fails, I want my program to try to reconnect without dying out. It must try reconnecting n number of times before finally giving up. Does anyone know how to achieve this ?

Replies are listed 'Best First'.
Re: SOAP::Lite reconnect
by cowboy (Friar) on Jun 14, 2006 at 22:06 UTC

    In the SOAP::Lite documentation have a look for the on_fault() method. It mentions the default action is to die on a transport error, or do nothing on other error conditions.

    Another alternative, would be to trap the die in an eval {}, although that will only trap the transport errors.

Re: SOAP::Lite reconnect
by shreya (Novice) on Jun 14, 2006 at 22:14 UTC
    I am aware of on_fault but not sure how that can help me reconnect n number of times.
      Try something like this (not the best example, I find SOAP::Lite quite powerful, but difficult to understand at the same time - untested code).
      my $soap; my $tries = 0; my $success = 0; while ($tries < 10 && !$success) { $success = 1; # set it to one, on fault, we'll set it to 0 $soap = SOAP::Lite -> on_fault(sub { $success = 0; }), -> uri('http...ect'); ++$tries; }
      Update: fixed typo (thanks ptum)
Re: SOAP::Lite reconnect
by jhourcle (Prior) on Jun 15, 2006 at 14:46 UTC

    With the slight chance that you weren't the same person to ask a rather similar question on the soaplite mailing list yesterday, see Eric Bridger's reply