I am attempting to access a web service using SOAP through Perl and am having issues calling the service\'s functions that require parameters. The XSD that dictates the SOAP cal
Use SOAP::WSDL to consume the service wsdl, it also marshals from and (optionally) to plain perl data structures for you. Highly recommended module.
Something like the following:
use SOAP::WSDL;
use Data::Dumper;
my $soap = SOAP::WSDL->new(
wsdl => 'http://server/pathtoservice?WSDL',
outputhash => 1
);
my $res = $soap->call('method', { foo => 1, bar =>2 });
die $res->faultstring if $res->fault;
print Dumper($res->result);
You can use wsdl2perl.pl to generate client stub code from wsdl. This makes things pretty easy. wsdl2perl.pl is part of SOAP::WSDL. Here is the sample code after you have generates client stub.
use MyInterfaces::SoapImplService::SoapPort;
my $soap = MyInterfaces::SoapImplService::SoapPort->new();
#calling method createRecipient which takes 2 parameterss:
#1. Complex type : recipient
#2. Complex type : authentication
my $response=$soap->createRecipient( { # MyTypes::createRecipient
recipient => { # MyTypes::Recipient
address => "test701\@test.com", # string
externalID => "test701\@test.com", # string
sourceDescription => "testing perl", # string
demographics => { # MyTypes::StringCollection
},
},
},,
{ # MyTypes::authentication
username=>'testuser' , password=>'pass'
},,
);
#you can find example code of calling every function in your "MyInterfaces\SoapImplService\SoapPort.pm" file.
You can try using SOAP::Lite if you are having problems with the WSDL:
remember, you can always use:
use SOAP::Lite qw(trace);
to see the exact XML you are sending to see how close you are.
I don't have time to test this out, but here is my best guess off the top of my head:
my $soap = SOAP::Lite
-> uri($uri)
-> on_action(sub { sprintf '"Call by on_action: %s"',shift})
-> proxy('http://192.168.1.100:8688/MyService/services/MyService.MyServicePort/');
my $id = SOAP::Data->type('int')->name('entityId')->value(0);
my $type= SOAP::Data->type('EntityType')->name('entityType')->value(NODE);
$soap->enumerateEntities($id, $param);