http://qs321.pair.com?node_id=380176

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

I'm trying to get aquainted with web services via SOAP::Lite, but I'm running into some problems.

Here is my SOAP server:

#! /usr/bin/perl use strict; use SOAP::Transport::HTTP; SOAP::Transport::HTTP::CGI -> dispatch_to( '/var/www/localhost/cgi-bin/soap_modules' ) -> handle;

My SOAP client:

#! /usr/bin/perl -w use strict; use SOAP::Lite; my $soap = SOAP::Lite -> proxy( 'http://dg.example.org/cgi-bin/soapserver.cgi' ) -> uri( 'http://dg.example.org/Greeter' ) -> on_fault( sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, +"\n"; }); my $greeter = $soap->call( new => 'Doug' )->result; print $soap->formal( $greeter )->result; __END__

And my Greeter class:

package Greeter; use strict; use warnings; sub new { my $self = shift; bless { name => shift }, 'Greeter'; } sub formal { my $self = shift; return "Welcome, $self->{name}."; } sub casual { my $self = shift; return "Howdy, $self->{name}!"; } 1;

When I run the client, I get the following:

Denied access to method (formal) in class (Greeter) at /usr/lib/perl5/ +site_perl/5.8.2/SOAP/Lite.pm line 2267.

Can anyone give me any pointers on why this is?


_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Replies are listed 'Best First'.
Re: Can't access class methods via SOAP
by gellyfish (Monsignor) on Aug 05, 2004 at 08:31 UTC

    See this for the reason for the message in a general sense. The problem you are having is that you are trying to autodispatch to the method formal and this is blocked because you have not specified the module it is in in the 'dispatch_to'. you could try adding the module to the dispatch_to list, specifying the full package name of the method or call it as a subroutine (with call) just the same as you did with new().

    /J\

      Thanks gellyfish, but I'm still having some problems. Here's how call() is used in the SOAP::Lite docs:

      # you should specify uri() my $soap = SOAP::Lite -> uri('http://my.own.site/CLASS') # <<< CLASS goes here # ..... other parameters ; my $obj = $soap->call(new => @parameters)->result; print $soap->call(method => $obj)->result; # $obj object will be updated here if necessary, # as if you call $obj->method() and method() updates $obj # Update of modified object MAY not work if server on another side # is not SOAP::Lite

      And here's what I've done:

      #! /usr/bin/perl -w use strict; use SOAP::Lite; my $soap = SOAP::Lite -> proxy( 'http://dg.homeunix.org/cgi-bin/soapserver.cgi' ) -> uri( 'http://dg.homeunix.org/Greeter' ) -> on_fault( sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, +"\n"; }); my $greeter = $soap->call( new => 'Doug' )->result; print $soap->call( formal => $greeter )->result; __END__

      ...and I get the same error as before.


      _______________
      DamnDirtyApe
      Those who know that they are profound strive for clarity. Those who
      would like to seem profound to the crowd strive for obscurity.
                  --Friedrich Nietzsche

        I think you need to go back to basics - this works:

        Server: #! /usr/bin/perl use strict; use SOAP::Transport::HTTP; use lib '/var/www/cgi-bin/soap_modules'; + use Greeter; SOAP::Transport::HTTP::CGI -> dispatch_to( '/var/www/cgi-bin/soap_modules','Greeter') -> handle; Client: #! /usr/bin/perl -w use strict; + use SOAP::Lite +autodispatch => proxy => 'http://localhost/cgi-bin/soaptest.cgi', uri => 'http://localhost/Greeter' , on_fault => sub { my($soap, $res) = @_; die ref $res ? $res->faultstring : $soap->transport->status, +"\n"; }; + my $greeter = Greeter->new('Doug'); print $greeter->formal();

        You will find that you get bitten like this when trying to do this kind of stuff.

        /J\