tjking has asked for the wisdom of the Perl Monks concerning the following question:
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:Client:#!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;
I'm currently getting the following output from the 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);
$ 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:
output: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'));
$ 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 | |
by tjking (Novice) on Jun 27, 2012 at 18:40 UTC |