NAME
SOAP::WSDL - SOAP with WSDL support
Overview
For creating Perl classes instrumenting a web service with a WSDL definition, read SOAP::WSDL::Manual.
For using an interpreting (thus slow and somewhat troublesome) WSDL based SOAP client, which mimics SOAP::Lite's API, read on.
SYNOPSIS
my $soap = SOAP::WSDL->new(
wsdl => 'file://bla.wsdl',
readable => 1,
);
my $result = $soap->call('MyMethod', %data);
DESCRIPTION
SOAP::WSDL provides easy access to Web Services with WSDL descriptions.
The WSDL is parsed and stored in memory.
Your data is serialized according to the rules in the WSDL.
The only transport mechanisms currently supported are http and https.
METHODS
new
Constructor. All parameters passed are passed to the corresponding methods.
call
Performs a SOAP call. The result is either an object tree (with outputtree), a hash reference (with outputhash), plain XML (with outputxml) or a SOAP::SOM object (with neither of the above set).
my $result = $soap->call('method', %data);
wsdlinit
Reads the WSDL file and initializes SOAP::WSDL for working with it.
Is called automatically from call() if not called directly before.
servicename
portname
call
You may set servicename and portname by passing them as attributes to wsdlinit:
$soap->wsdlinit(
servicename => 'MyService',
portname => 'MyPort'
);
CONFIGURATION METHODS
outputtree
When outputtree is set, SOAP::WSDL will return an object tree instead of a SOAP::SOM object.
You have to specify a class_resolver for this to work. See <class_resolver|class_resolver>
class_resolver
Set the class resolver class (or object).
Class resolvers must implement the method get_class which has to return the name of the class name for deserializing a XML node at the current XPath location.
Class resolvers are typically generated by using the to_typemap method on a SOAP::WSDL::Definitions objects.
Example:
XML structure (SOAP body content):
<Person>
<Name>Smith</Name>
<FirstName>John</FirstName>
</Person>
Class resolver
package MyResolver;
my %typemap = (
'Person' => 'MyPersonClass',
'Person/Name' => 'SOAP::WSDL::XSD::Typelib::Builtin::string',
'Person/FirstName' => 'SOAP::WSDL::XSD::Typelib::Builtin::string',
);
sub get_class { return $typemap{ $_[1] } };
1;
You'll need a MyPersonClass module in your search path for this to work - see SOAP::WSDL::XSD::ComplexType on how to build / generate one.
servicename
$soap->servicename('Name');
Sets the service to operate on. If no service is set via servicename, the first service found is used.
Returns the soap object, so you can chain calls like
$soap->servicename->('Name')->portname('Port');
portname
$soap->portname('Name');
Sets the port to operate on. If no port is set via portname, the first port found is used.
Returns the soap object, so you can chain calls like
$soap->portname('Port')->call('MyMethod', %data);
no_dispatch
When set, call() returns the plain request XML instead of dispatching the SOAP call to the SOAP service. Handy for testing/debugging.
ACCESS TO SOAP::WSDL's internals
get_client / set_client
Returns the SOAP client implementation used (normally a SOAP::WSDL::Client object).
Useful for enabling tracing:
# enable tracing via 'warn'
$soap->get_client->set_trace(1);
# enable tracing via a custom facility -
# Log::Log4perl in this case...
$soap->get_client->set_trace(sub { Log::Log4perl->get_logger->info(@_) } );
EXAMPLES
See the examples/ directory.
Differences to previous versions
WSDL handling
SOAP::WSDL 2 is a complete rewrite. While SOAP::WSDL 1.x attempted to process the WSDL file on the fly by using XPath queries, SOAP:WSDL 2 uses a SAX filter for parsing the WSDL and building up a object tree representing it's content.
The object tree has two main functions: It knows how to serialize data passed as hash ref, and how to render the WSDL elements found into perl classes.
Yup your're right, there's a builting code generation facility. Read SOAP::WSDL::Manual for using it.
no_dispatch
call() with outputtxml set to true now returns the complete SOAP envelope, not only the body's content.
outputxml
call() with outputxml set to true now returns the complete SOAP envelope, not only the body's content.
servicename/portname
Both servicename and portname can only be called after calling wsdlinit().
You may pass the servicename and portname as attributes to wsdlinit, though.
Differences to SOAP::Lite
Output formats
In contrast to SOAP::Lite, SOAP::WSDL supports the following output formats:
SOAP::SOM objects.
This is the default. SOAP::Lite is required for outputting SOAP::SOM objects.
Object trees.
This is the recommended output format. You need a class resolver (typemap) for outputting object trees. See class_resolver above.
Hash refs
This is for convnience: A single hash ref containing the content of the SOAP body.
xml
See below.
outputxml
SOAP::Lite returns only the content of the SOAP body when outputxml is set to true. SOAP::WSDL returns the complete XML response.
Auto-Dispatching
SOAP::WSDL does does not support auto-dispatching.
This is on purpose: You may easily create interface classes by using SOAP::WSDL::Client and implementing something like
sub mySoapMethod {
my $self = shift;
$soap_wsdl_client->call( mySoapMethod, @_);
}
You may even do this in a class factory - see wsdl2perl.pl for creating such interfaces.
Debugging / Tracing
While SOAP::Lite features a global tracing facility, SOAP::WSDL allows to switch tracing on/of on a per-object base.
This has to be done in the SOAP client used by SOAP::WSDL - see get_client for an example and SOAP::WSDL::Client for details.
Bugs and Limitations
SOAP Headers are not supported
There's no way to use SOAP Headers with SOAP::WSDL yet.
Apache SOAP datatypes are not supported
You currently can't use SOAP::WSDL with Apache SOAP datatypes like map.
If you want this changed, email me a copy of the specs, please.
outputhash
outputhash is not implemented yet.
Unsupported XML Schema definitions
The following XML Schema definitions are not supported:
choice group union simpleContent complexContent
Serialization of hash refs dos not work for ambiguos values
If you have list elements with multiple occurences allowed, SOAP::WSDL has no means of finding out which variant you meant.
Passing in item => [1,2,3] could serialize to
<item>1 2</item><item>3</item> <item>1</item><item>2 3</item>
Ambiguos data can be avoided by passing an objects as data.
XML Schema facets
Almost no XML schema facets are implemented yet. The only facets currently implemented are:
fixed default
The following facets have no influence yet:
minLength maxLength minInclusive maxInclusive minExclusive maxExclusive pattern enumeration
ACKNOWLEDGMENTS
There are many people out there who fostered SOAP::WSDL's developement. I would like to thank them all (and apologize to all those I have forgotten).
Giovanni S. Fois wrote a improved version of SOAP::WSDL (which eventually became v1.23)
Damian A. Martinez Gelabert, Dennis S. Hennen, Dan Horne, Peter Orvos, Marc Overmeer, Jon Robens, Isidro Vila Verde and Glenn Wood spotted bugs and/or suggested improvements in the 1.2x releases.
Andreas 'ACID' Specht constantly asked for better performance.
Numerous people sent me their real-world WSDL files for testing. Thank you.
Paul Kulchenko and Byrne Reese wrote and maintained SOAP::Lite and thus provided a base (and counterpart) for SOAP::WSDL.
LICENSE
Copyright 2004-2007 Martin Kutter.
This file is part of SOAP-WSDL. You may distribute/modify it under the same terms as perl itself
AUTHOR
Martin Kutter E<lt>martin.kutter fen-net.deE<gt>