I am writing a small Perl program to atest the availbility of a webservice.
So the idea is to call a known method of a known webservice and check the result.
To make the program flexible and to allow me to test several webservices I pass te following params from the command line
SOAP-ping.pl [ -u url ] [ -p proxy ] [ -m method ]
eg: perl SOAP-Ping.pl -u http://www.soaplite.com/Demo -p http://services.soaplite.com/hibye.cgi -m hi()
I pick up the params using the use Getopt::Std;
and pass them to the SOAP::Lite object.
Passing the URL & proxy is not an issue but the method is causing me a headegde.
As I get the method as a variable (string) I can not pass it to SOAP::Lite as this requires it in a different form.
Expand|Select|Wrap|Line Numbers
- my $soap = SOAP::Lite
- -> uri($url)
- -> proxy($proxy);
- # this ain't working
- my $result = $soap->$method;
- #The code that works is
- my $result = $soap->hi();
Here is the full version of my test program
Expand|Select|Wrap|Line Numbers
- #!/usr/bin/perl -w
- # http://guide.soaplite.com/#writing%20a%20client
- # http://www.robertprice.co.uk/robblog...ith_Perl.shtml
- # Usage: SOAP-ping.pl [ -u url ] [ -p proxy ] [ -m method ]
- ####################################
- # Modules #
- ####################################
- use Getopt::Std;
- use Time::HiRes qw (time);
- use SOAP::Lite;
- ####################################
- # Globals #
- ####################################
- ####################################
- # Get the parameters from the user #
- ####################################
- %options=();
- getopts("u:p:m:",\%options);
- my $url = defined($options{u}) ? $options{u} : "http://localhost/";
- my $proxy = defined($options{p}) ? $options{p} : "http://localhost/";
- my $method = defined($options{m}) ? $options{m} : "";
- ####################################
- # Test Connection #
- ####################################
- printf("Url: %s\nProxy %s\nMethod: %s\n",$url, $proxy, $method);
- # Calculate the time it takes
- my $start = time();
- my $soap = SOAP::Lite
- -> uri($url)
- -> proxy($proxy);
- my $result = $soap->hi();
- unless ($result->fault)
- {
- print $result->result(),"\n";
- }
- else
- {
- print join ', ',
- $result->faultcode,
- $result->faultstring;
- }
- my $soaptime = time() - $start;
- printf("%d\n%d\n",$soaptime * 1000, $soaptime * 1000);
perl SOAP-Ping.pl -u http://www.soaplite.com/Demo -p http://services.soaplite.com/hibye.cgi -m hi()
Thx in advance for anyone helping me out here
Regards
Marc