Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Troubles accessing data using SOAP::Lite and WSDL service

by beaufils (Novice)
on Jan 19, 2012 at 10:33 UTC ( #948747=perlquestion: print w/replies, xml ) Need Help??
beaufils has asked for the wisdom of the Perl Monks concerning the following question:

Here is a code snippet I use to access some SOAP methods available on a bibliographic system:

#!/usr/bin/perl use SOAP::Lite;# +trace => qw(debug); my $service = SOAP::Lite->service(' +ref.php?wsdl'); my $result = $service->getRefInstance(); use Data::Dumper; print Dumper($result); print $result->result,"\n";

I always get that reply

$VAR1 = { 'string' => [ 'ads', 'afssa', # [...] values cut for clarity 'telearn', 'tematice' ] }; Can't call method "result" on unblessed reference at ./ line 12 +.

The result is announced as (in the webservices documentation), and thus should be, an ArrayOfStrings.

Any idea of I am doing wrong? (Why the hell the result is not blessed?)

I am really desperated...

Replies are listed 'Best First'.
Re: Troubles accessing data using SOAP::Lite and WSDL service
by Anonymous Monk on Jan 19, 2012 at 11:33 UTC
Re: Troubles accessing data using SOAP::Lite and WSDL service
by roboticus (Chancellor) on Jan 19, 2012 at 10:54 UTC


    I've not used SOAP, so I don't know why it did anything. But you mention that the result should be an array of strings, and the $result variable clearly contains an array of strings within a hash reference. So perhaps you have what you need. If you just want to print the array of string values, try:

    print join(", ", @{$$result{string}}), "\n";


    When your only tool is a hammer, all problems look like your thumb.

Re: Troubles accessing data using SOAP::Lite and WSDL service
by TomDLux (Vicar) on Jan 19, 2012 at 19:12 UTC

    ArrayofStrings is a way of saying you get back an array, and the array elements are strings. You seem to think ArrayofStrings is an object type.

    Why don't you try running the program under the debugger: perl -d and have the program run to the point where $result has been assigned its value: c linenumber eg c 186. Then you can experiment typing expressions and having perl tell you what you asked for.

    DB<1> print $results HASH(0x8421888) # So $results stores a reference to a hash DB<2> print join ', ', keys %$results string # So the hash has a single key, 'string' DB<3> print $results->{string} ARRAY(0x8421438) # So the hash stores a reference to an array as the value for its only + key DB<4>print $results->{string}[0] # This part left as an exercise for the reader.

    When you don't understand what's happening, fire up the debugger and experiment. No one ever blew up their computer running a debugger ( except that one guy, we don't mention him.)

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re: Troubles accessing data using SOAP::Lite and WSDL service
by tokpela (Chaplain) on Jan 20, 2012 at 03:03 UTC

    This is not a direct response to your question but I have found that XML::Compile is pretty good at making SOAP easier for me.

    If you have a WSDL, then I recommend using the explain method from XML::Compile::WSDL11 which will output the data structures in Perl for you to use and/or expect in the SOAP response.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://948747]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2018-05-26 14:14 GMT
Find Nodes?
    Voting Booth?