SOAP Server (mod_perl)


If you'd like to avoid the overhead of reading SOAP::Lite and your program into memory on every invocation you can run your CGI under Apache::Registry, or you can create a mod_perl handler.


In your httpd.conf


     1	<Location /soap>
     2	  SetHandler perl-script
     3	  PerlHandler SOAP::Handler 
     4	</Location>


a file in your PERL5LIB: SOAP/Handler.pm

     1	package SOAP::Handler;
     2	
     3	use strict;
     4	use SOAP::Transport::HTTP;
     5	
     6	my $server = SOAP::Transport::HTTP::Apache
     7	    ->dispatch_to( '/path/to/modules' );
     8	
     9	sub handler { 
    10	    $server->handler( @_ ); 
    11  }
    12 
    13  1;

a file: /path/to/modules/xmethods-CurrencyExchange.pm

     1	package xmethods-CurrencyExchange;
     2
     3  use SOAP::Lite;
     4
     5	sub getRate {
     6	    my ( $country1, $country2 ) = @_;
     7	    my $result = calculate( $country1, $country2 );
     8	    return( SOAP::Data->name( 'Result' => $result )->type( 'float' ) );
     9	}
    10	
    11	1;