Mojolicious::Plugin::SOAP::Server - implement a SOAP service
use Mojolicious::Lite; use Mojo::File 'curfile'; plugin 'SOAP::Server' => { wsdl => curfile->sibling('nameservice.wsdl'), xsds => [curfile->sibling('nameservice.xsd')], controller => SoapCtrl->new(x => '1'), endPoint => '/SOAP' }; app->start; package SoapCtrl; use Mojo::Base -base,-signatures; has 'x' => 2; sub getCountries ($self,$server,$params,$controller) { return { country => [qw(Switzerland Germany), $self->x] }; } sub getNamesInCountry ($self,$server,$params,$controller) { my $name = $params->{parameters}{country}; $controller->log->debug("Test Message"); if ($name eq 'Die') { die { status => 401, text => 'Unauthorized' }; } return { name => [qw(A B C),$name] }; }
The Mojolicious::Plugin::SOAP::Server is a thin wrapper around XML::Compile::SOAP::Daemon which makes it pretty simple to implement SOAP services in perl.
The plugin supports the following configuration options:
A wsdl filename with definitions for the services provided
An array pointer with xsd files for the data types used in the wsdl.
A mojo Object whose methods match the service names defined in the wsdl file.
sub methodName ($self,$server,$params,$controller) {
see example folder for inspiration.
A default callback to be called if the requested method does not exist in the controller.
Where to 'mount' the SOAP service.
This is really just a very thin layer on top of Mark Overmeers great XML::Compile::SOAP::Daemon module. Thanks Mark!
Tobias Oetiker, <tobi@oetiker.ch>
Copyright OETIKER+PARTNER AG 2019
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10 or, at your option, any later version of Perl 5 you may have available.
To install Mojolicious::Plugin::SOAP::Server, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::SOAP::Server
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::SOAP::Server
For more information on module installation, please visit the detailed CPAN module installation guide.