|
Hello,
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.
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();
How can I make this last line variable so I can pass the method via the command line instead of 'hard coded' in de code?
Here is the full version of my test program
#!/usr/bin/perl -w
# http://guide.soaplite.com/#writing%20a%20client
# http://www.robertprice.co.uk/robblo...With_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);
To test it:
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
|
|
|
I take it you want to call a function which is named... whatever the content of a specific variable is.
if so then try:
my $result = $soap->&$method;
|
|
|
Tried that already before but I get the error message
syntax error at SOAP-Ping.pl line 41, near "->&"
:-((
|
|
|
|
|
|
|
// |