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

Hello,

I am having trouble extracting data from my SOAP::Lite program. I can connect to the WSDL just fine. It even returns data. (I know because Dumper tells me it is there). My problem is trying to put said data into a variable. Here is my code:-------------------------------------------------------------------

#! /usr/bin/perl use SOAP::Lite +trace => 'debug'; use Data::Dumper; # .NET web services expect / as a separator # for uri and method. my $lite = SOAP::Lite->new()->on_action(sub { join '/', @_ } ) ->proxy('http://somewhere.net/rjam-request-service/svc/RequestServic +e/3?wsdl') ->readable(1); $response = $lite->call( SOAP::Data->name('fetchAndLock') ->attr({ 'xmlns', 'http://somewhere.net/request/servic +e/3' }), SOAP::Data->name("first")->value(3), SOAP::Data->name("max")->value(1), SOAP::Data->name("provider")->value('homeFolderWin'), SOAP::Data->name("action")->value('bestMatch'), SOAP::Data->name("state")->value('PLACED') ); my $tmp_data = $response->valueof('[1]'); print Dumper($tmp_data); my $lts=$tmp_data->dataof('//fetchAndLockResponse/request/lockedTimes' +);

and here is what is returned on my command prompt (note that I cleaned up the response a bit to make it more readable): -------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instanc +e" xmlns:S OAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="ht +tp://schem as.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSc +hema" SOAP -ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > <SOAP-ENV:Body > <fetchAndLock xmlns="http://somewhere.net/request/service/3" > <first xsi:type="xsd:int" >3</first> <max xsi:type="xsd:int" >1</max> <provider xsi:type="xsd:string" >homeFolderWin</provider> <action xsi:type="xsd:string" >bestMatch</action> <state xsi:type="xsd:string" >PLACED</state></fetchAndLock></SOAP-ENV:Body></SOAP-ENV:Envelop +e> SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 200 OK Connection: close Date: Tue, 14 Aug 2012 12:31:38 GMT Server: IBM_HTTP_Server Content-Language: en-US Content-Type: text/xml; charset=UTF-8 Client-Date: Tue, 14 Aug 2012 12:31:38 GMT Client-Peer: 169.81.175.20:80 Client-Response-Num: 1 Client-Transfer-Encoding: chunked <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <fetchAndLockResponse xmlns="http://somewhere.net/request/serv +ice/3"> <request> <id>210</id> <client>TESTING</client> <externalId>homefoldertest1241</externalId> <externalParentId>TODO</externalParentId> <provider>homeFolderWin</provider> <action>bestMatch</action> <priority>1</priority> <actionTime>2012-07-13T16:20:34.993Z</actionTime> <state>PLACED</state> <result>NONE</result> <locked>true</locked> <lockedTimes>43</lockedTimes> <arguments> <name>sid</name> <valueString>F030624</valueString> </arguments> <arguments> <name>domain</name> <valueString>NAEAST</valueString> </arguments> </request> </fetchAndLockResponse> </soap:Body> </soap:Envelope> Can't call method "dataof" on unblessed reference at test.pl line 28. ---------------------------------------------------------------------- +----------------
why cannot I extract the locked times from using the dataof part? (I have the same problem with valueof). Any help would be greatly appreciated. Frank

Replies are listed 'Best First'.
Re: soap::lite - Can't call method "dataof" on unblessed reference
by tobyink (Canon) on Aug 14, 2012 at 13:58 UTC

    $tmp_data is not an object, so you can't call methods on it. Try dumping $tmp_data and see what it looks like.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Here is the dumped output of tmp_data:
      $VAR1 = { 'fetchAndLockResponse' => { 'request' => { 'priority' => '1', 'provider' => 'homeFolderWin', 'locked' => 'true', 'externalId' => 'homefoldertest1241', 'actionTime' => '2012-07-13T16:20:34.993Z', 'state' => 'PLACED', 'client' => 'TESTING', 'externalParentId' => 'TODO', 'action' => 'bestMatch', 'arguments' => { 'name' => 'domain', 'valueString' => 'NAEAST' }, 'id' => '210', 'lockedTimes' => '70', 'result' => 'NONE' } } };

      Interestingly enough, dumper misses some code that is part of the original soap:Envelope:

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> +<soap:Body ><fetchAndLockResponse xmlns="http://myid.jpmchase.net/request/service +/3"><reque st><id>210</id><client>TESTING</client><externalId>homefoldertest1241< +/externalI d><externalParentId>TODO</externalParentId><provider>homeFolderWin</pr +ovider><ac tion>bestMatch</action><priority>1</priority><actionTime>2012-07-13T16 +:20:34.993 Z</actionTime><state>PLACED</state><result>NONE</result><locked>true</ +locked><lo ckedTimes>70</lockedTimes><arguments><name>sid</name><valueString>F030 +624</value String></arguments><arguments><name>domain</name><valueString>NAEAST</ +valueStrin g></arguments></request></fetchAndLockResponse></soap:Body></soap:Enve +lope>

      cleaning up the above and making it readable, we see:

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <fetchAndLockResponse xmlns="http://myid.jpmchase.net/request/ +service/3"> <request> <id>210</id> <client>TESTING</client> <externalId>homefoldertest1241</externalId> <externalParentId>TODO</externalParentId> <provider>homeFolderWin</provider> <action>bestMatch</action> <priority>1</priority> <actionTime>2012-07-13T16:20:34.993Z</actionTime> <state>PLACED</state> <result>NONE</result> <locked>true</locked> <lockedTimes>43</lockedTimes> <arguments> <name>sid</name> <valueString>F030624</valueString> </arguments> <arguments> <name>domain</name> <valueString>NAEAST</valueString> </arguments> </request> </fetchAndLockResponse> </soap:Body> </soap:Envelope>

      note the two sets of "arguments". what I need out of all of the above code is just ID (which is 210), and the valuestring for SID (which is F030624) and the valuestring for domain (which is NAEAST). any ideas would be greatly appreciated.</code>