Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

SOAP::Lite remote objects

by tjking (Novice)
on Jun 26, 2012 at 21:04 UTC ( [id://978509]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I'm trying to create a webservices wrapper for a module whose structure doesn't seem to be compatible with direct dispatching. I need to build up a bunch of state before executing the module calls from the server, but there seems to be concurrency issues with the approach I'm taking, and wonder if anyone can spot my mistake in the following stub.

Server:
#!perl -w use SOAP::Transport::HTTP; SOAP::Transport::HTTP::Daemon ->new(LocalPort=>1111,ReuseAddr=>1) -> dispatch_to('TestWrapper') -> handle; package TestWrapper; use Data::Dumper; sub new { my $self = shift; my $class = ref($self) || $self; return bless {} => $class; } sub put { my ($self, $key, $val) = @_; $self->{_HASH}{$key} = $val; } sub get { my ($self, $key) = @_; return $self->{_HASH}{$key}; } 1;
Client:
use strict; use warnings; use SOAP::Lite; my $soap = SOAP::Lite -> uri('http://localhost:1111/TestWrapper') -> proxy('http://localhost:1111/'); my $t1 = $soap->new(); $t1->put('element1', 'value1'); my $t2 = $soap->new(); $t2->put('element1', 'value2')->result; printf("t1 : %s\n", $t1->get('element1')->result); printf("t2 : %s\n", $t2->get('element1')->result);
I'm currently getting the following output from the client:
$ perl client.pl t1 : value2 t2 : value2

Both references seem to end up pointing at the same object, causing the hash entry to get overwritten, and this even happens if I create the objects in two separate scripts and run them concurrently. However, if I create the objects directly (i.e. not via SOAP), everything works as expected:

use TestWrapper; my $t1 = new TestWrapper; $t1->put('element1', 'value1'); my $t2 = new TestWrapper; $t2->put('element1', 'value2'); printf("t1 : %s\n", $t1->get('element1')); printf("t2 : %s\n", $t2->get('element1'));
output:
$ perl standalone.pl t1 : value1 t2 : value2

Any input would be most appreciated. I'm using ActivePerl 5.14 and SOAP::Lite 0.714.

Replies are listed 'Best First'.
Re: SOAP::Lite remote objects
by McA (Priest) on Jun 27, 2012 at 02:21 UTC
    Hi,

    I can't run the code on my side. So what I'm saying is a guess looking at your code and at the documentation.

    Are you sure that the code snippet my $t1 = $soap->new(); does a remote call to 'new' to instantiate an object on the remote site? I guess not. I assume that 'new' is called on SOAP::Lite.

    Is my $t1 = $soap->call('new'); the solution?

    Probaby you make a cross check calling your object creation method in TestWrapper not 'new' but e.g. 'mynew'.

    Best regards
    McA

      Yes, it's instantiating a TestWrapper object, or it wouldn't be giving the client output that I'm already getting. Renaming the constructor results in "Can't locate object method "put" via package "SOAP::SOM" at client.pl line 10.". Using $soap->call('new') instead of $soap->new() makes no difference either way.

      The problem is, the SOAP::Lite documentation and examples that are out there are severely out of date, and many do not work at all with the current version. The only example I could find for remote instantiation was this one, which does work. However, only the constructor takes a user-defined argument, the subsequent method call is static, and only takes the object returned by call(). Unfortunately, I can't seem to figure out how to get this to work with regular methods that take additional arguments (other than the object itself).

      Thanks for the input!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://978509]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 09:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found