how to retrieve the result from a soap call
- hi SOAP::Lite experts
I met a problem in retrieve SOAP call result.
when i can a remote method
use SOAP::Lite;# + trace => qw(method debug);
my $PROXY = "http://myhost/";
my $NS = "urn:testing";
my $soap = SOAP::Lite
my $method = SOAP::Data->name('foobar');
my @params = SOAP::Data->name("a" => $a,
"b" => $b );
if i call $soap->call($method => @params)
it returns a correct XML response.
how every if i call it the following way, it prompt that the result method is not found:
my $ret= $soap->call($method => @params)
Can't call method "result" without a package or object reference at /path/to/module.pm line 101.
I am very new to SOAP::Lite, and i see examples from SOAP::Lite are doing it this way, but it seems not work for me.
Can anybody help me on this?
Thank you very much.
In your example, $ret is really a soap response object (SOM) unless something happened to cause an exception (die or croak) to occur. You can read the data access methods in: http://search.cpan.org/perldoc?SOAP::SOM
But in general you can use XPath methods to retrieve data. Here is an example:
my $resp= $soap->call( $method => @params); # changed ret to resp
die "Fault occurred: " . $resp->faultstring if $resp && $resp->fault;
# grab data from response
print "Cat: " . $resp->match('//cat') if $resp->match('//cat'); ## not a great example...
In your example the 'result' method will only return the data in a method Response block. This is kind of confusing but basically the server needs to return something that looks like:
If it doesn't then the 'result' method will return undef even though there might a SOAP repsonse with data from your service. Otherwise, you can grab the other data in the SOAP response with the method above.