Loading ...
Sorry, an error occurred while loading the content.

SOAP::Lite Server dispatching strict OO perl modules to non-perl clients

Expand Messages
  • toddkuebler
    I m running into a problem with making strict OO perl modules available to other languages. I m hoping it is something simple and obvious that I m missing.
    Message 1 of 1 , May 7, 2003
    • 0 Attachment
      I'm running into a problem with making strict OO perl modules
      available to other languages. I'm hoping it is something simple and
      obvious that I'm missing. (code demostrating the issue is included
      inline below)

      When SOAP clients (including SOAP::Lite if it uses the non-OO
      signature) call a strict OO perl module being served by SOAP::Lite
      that has something like $self->{somevar} in the method being called
      they fail with the error:

      Can't use string ("Cow") as a HASH ref while "strict refs" in use at
      Cow.pm line 32.

      Not suprisingly, running the perl debugger reveals that $self is a
      string when called that way, so both the error and the solution (no
      strict 'refs') make sense. Unfortunately I don't have control of the
      Perl modules being served or the server, I just have network access to
      the SOAP service. Changing the module to support non-OO calls (adding
      "no strict 'refs';") is not an option unfortunately.

      How do I get around this from the client end? I need to access the
      client via java, and short of making perl calls in my java code and
      using the perl OO client signature, or writing a perl proxy service
      that maps the OO calls to simple function calls I can't for the life
      of me figure out how to hack it. I've got a soap scope up and am
      comparing each different type of request, but can't make sense of it
      so far. I'll post a reply if I figure out what to add to the request
      to trick SOAP::Lite into thinking I'm calling a perl object (this
      makes me shudder in revulsion).

      How come the documentation doesn't deal with this issue, it seems like
      a fairly common one?

      >>>>>>> Cow.pm >>>>>>>>>>>
      package Cow;

      use strict;
      #no strict 'refs';

      sub new {
      my $this = shift;
      my $class = ref ($this) || $this;
      my $self = {};
      bless $self, $class;
      $self->{hello} = "moooo";
      return $self;

      sub speak {
      my ( $self, @junk ) = @_;

      return $self->{hello};

      >>>>>>>>>> farm.cgi >>>>>>>>>>>>>>>

      use Cow;

      use SOAP::Transport::HTTP;

      -> dispatch_to('Cow')
      -> handle;
      >>>>>>>>>> farmer.pl >>>>>>>>>>>>

      use SOAP::Lite;
      use Cow;
      use strict;

      print "Using perl module OO:\n";
      my $cow = new Cow;
      print "speak: ", $cow->speak(), "\n";

      # uncomment to notice same behavior calling the module
      # without soap in a non-OO way
      #print "Using perl module non-OO:\n";
      #print "speak: ", Cow->speak();

      print "Using web service in OO way:\n";

      use SOAP::Lite
      +autodispatch =>
      uri => 'Cow',
      proxy => 'http://localhost/cgi-bin/soap/farm.cgi',
      on_fault =>
      sub {
      my( $soap, $res ) = @_;
      die ref $res ? $res->faultstring :

      my $ws = new();

      print "speak: ", $ws->speak(), "\n";


      print "Using web service in non-OO way:\n";

      print "speak: ", my $soap = new SOAP::Lite
      -> uri('Cow')
      -> proxy('http://localhost/cgi-bin/soap/farm.cgi')
      -> on_fault(sub { my($soap, $res) = @_;
      die ref $res ? $res->faultstring :
      $soap->transport->status, "\n
      -> speak()
      -> result(), "\n";

    Your message has been successfully submitted and would be delivered to recipients shortly.