Skip to content

Instantly share code, notes, and snippets.

@dex4er
Created November 15, 2011 19:07
Show Gist options
  • Save dex4er/1367998 to your computer and use it in GitHub Desktop.
Save dex4er/1367998 to your computer and use it in GitHub Desktop.
XML::Compile::SOAP example client
#!/usr/bin/env perl
use warnings;
use strict;
use XML::Compile::WSDL11;
use XML::Compile::SOAP11;
use XML::Compile::Transport::SOAPHTTP;
use HTTP::Tiny;
use YAML::Tiny;
my $wsdl = XML::Compile::WSDL11->new(
HTTP::Tiny->new->get('http://soaptest.parasoft.com/calculator.wsdl')->{content},
);
use URI; #
my $uri = URI->new($wsdl->endPoint); # additional HTTP authorization
$uri->userinfo('user:password'); #
#
my $http = XML::Compile::Transport::SOAPHTTP->new( # setting new transport
address => $uri->as_string, # with explicit address
); #
#
my $transport = $http->compileClient( # SOAPAction header
action => 'add', #
); #
my $call = $wsdl->compileClient(
operation => 'add',
sloppy_floats => 1,
transport => $transport, # optional for default transport
# transport => sub { die $_[0]->toString }, # debugging: only XML output
);
my $request = {
x => 2,
y => 2,
};
my ($response, $trace) = $call->($request);
print "---\n";
$trace->printRequest;
print Dump({Data => $request}), "\n";
print "---\n";
$trace->printResponse;
print Dump({Data => $response}), "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment