SOAP-XML-Client
view release on metacpan or search on metacpan
lib/SOAP/XML/Client/Generic.pm view on Meta::CPAN
# Create an object with basic SOAP::Lite config stuff
my $soap_client = SOAP::XML::Client::Generic->new({
uri => 'http://www.yourdomain.com/services',
proxy => 'http://www.yourproxy.com/services',
xmlns => 'http://www.yourdomain.com/services',
soapversion => '1.1', # defaults to 1.1
timeout => '30', # detauls to 30 seconds
strip_default_xmlns => 1, # defaults to 1
});
# Create the following XML:
my $user_id = '900109';
my $xml = "<userId _value_type='long'>$user_id</userId>";
###########
# Warning: you might have to supply data types (using _value_type)
# for each field, depending on the service you are talking to
###########
# Actually do the call
if( $soap_client->fetch({
'method' => 'GetActivity',
'xml' => $xml,
}) ) {
# Get result as a string
my $xml_string = $soap_client->result();
# Get result as a XML::LibXML object
my $xml_libxml_object = $soap_client->result_xml();
} else {
# Got an error
print "Problem using service:" . $soap_client->error();
}
=head1 methods
=head2 new()
my $soap_client = SOAP::XML::Client::Generic->new({
uri => 'http://www.yourdomain.com/services',
proxy => 'http://www.yourproxy.com/services',
xmlns => 'http://www.yourdomain.com/services',
soapversion => '1.1', # defaults to 1.1
timeout => '30', # detauls to 30 seconds
strip_default_xmlns => 1, # defaults to 1
});
This constructor requires uri, proxy and xmlns to be
supplied, otherwise it will croak.
strip_default_xmlns is used to remove xmlns="http://.../"
from returned XML, it will NOT alter xmlns:FOO="http//.../"
set to '0' if you do not wish for this to happen.
=head2 header()
my $header = SOAP::Header->name(
SomeDomain => {
Username => "a_user",
Password => 'xxxxx',
}
)->uri('http://www.thedomain.com/')->prefix('');
$soap_client->header($header);
Add a soap header to the soap call, probably useful if there is
credential based authenditcation
=head2 fetch()
# Generate the required XML (you don't need the SOAP wrapper or method part of the XML
my $user_id = '900109';
my $xml = "<userId _value_type='long'>$user_id</userId>";
if($soap_client->fetch({ method => 'GetActivity', xml => $xml }) {
# Get result as a string
my $xml_string = $soap_client->result();
# Get result as a XML::LibXML object
my $xml_libxml_object = $soap_client->result_xml();
} else {
# There was some sort of error
print $soap_client->error() . "\n";
}
This method actually calls the web service, it takes a method name
and an xml string. If there is a problem with either the XML or
the SOAP transport (e.g. web server error/could not connect etc)
undef will be returned and the error() will be set.
Each node in the XML supplied (either by string or from a filename)
can have _value_type defined or the submitted format may
default to 'string' (depending on SOAP::Data::Builder).
You can supply 'filename' rather than 'xml' and it will read in from
the file.
We check for Fault/faultstring in the returned XML,
anything else you'll need to check for yourself.
=cut
=head2 error()
$soap_client->error();
If fetch returns undef then check this method, it will either be that the filename you
supplied couldn't be read, the XML you supplied was not correctly formatted (XML::LibXML
could not parse it), there was a transport error with the web service or Fault/faultstring
was found in the XML returned.
=head2 results();
my $results = $soap_client->results();
( run in 0.661 second using v1.01-cache-2.11-cpan-39bf76dae61 )