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.


In reply to SOAP::Lite remote objects by tjking

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.