perlquestion
mrguy123
Hi monks, I apologize in advance for the length of this one:<br>
My job for the past few months has been retrieving webpages from the internet for a meta search engine. Until now I have done so using basic url queries (e.g <code> http://www.imdb.com/finds=all&q=cats </code> for all movies with cats in the title). For this I have used the LWP::UserAgent with much satisfaction. In the past few weeks I have been trying to understand and retrieve web pages with SOAP. The information I had in my hand on how to do so (besides the web) were a few programs that my predecessor wrote that uses SOAP. In all these programs but one, he used the LWP::UserAgent to retrieve the web pages, sending the SOAP content as part of the request object in POST. This demo is an example of such a search request (it needs IP-authentication to work, but it sends all the required information): <code>
#!/usr/bin/perl
use HTTP::Cookies;
use strict;
use LWP::UserAgent;
{
my $ua = new LWP::UserAgent;
$ua->cookie_jar(HTTP::Cookies->new());
push @{$ua->requests_redirectable}, 'POST';
my $search_command = "http://wok-ws.isiknowledge.com/esti/soap/SearchRetrieve";
my $content = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><namesp1:search xmlns:namesp1="http://wok-ws.isiknowledge.com/esti/soap/SearchRetrieve?wsdl"><databaseId xsi:type="xsd:string">DIIDW</databaseId><query xsi:type="xsd:string">TS=(create)</query><editions xsi:type="xsd:string"/><firstRec xsi:type="xsd:int">1</firstRec><numRecs xsi:type="xsd:int">1</numRecs></namesp1:search></SOAP-ENV:Body></SOAP-ENV:Envelope>';
my $header = new HTTP::Headers (
'Content-Type' => 'text/xml; charset=utf-8',
'User-Agent' => 'PHP SOAP 0.1',
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => "http://wok-ws.isiknowledge.com/esti/soap/SearchRetrieve?wsdl#search",
);
my $req = new HTTP::Request('POST',$search_command,$header,$content);
my $res = $ua->request($req);
print $req->as_string."\n";
my $response = $res->headers_as_string();
my $response .= $res->content;
print "---response---\n$response\n";
}
</code>
As I have said, this was the way most of the programs sent their info. However, this particular program used the SOAP::Lite module to create the same search request. The code is: <code>
#!/exlibris/metalib/m4_b/product/bin/perl
sub BEGIN {
unshift (@INC, $ENV{'aleph_ext'});
unshift (@INC, "$ENV{'aleph_product'}"."/perl/lib/site_perl/5.005");
unshift (@INC, "$ENV{'aleph_product'}"."/perl/lib/site_perl/5.005/i686-linux");
}
use SOAP::Lite+trace => 'debug';
my $soap_request = SOAP::Lite->new();
$soap_request->uri("http://wok-ws.isiknowledge.com/esti/soap/SearchRetrieve?wsdl");
$soap_request->proxy("http://wok-ws.isiknowledge.com/esti/soap/SearchRetrieve");
$service = 'search';
my $soap_response = $soap_request->$service(
SOAP::Data->name(databaseId => 'DIIDW'),
SOAP::Data->name(query => 'TS=(create)'),
SOAP::Data->name(editions => ""),
SOAP::Data->name(firstRec => '1'),
SOAP::Data->name(numRecs => '1'),
);
</code>
As you can see, the code is much more simple, and basically creates the same request from scratch. If you run both demos, you should get the same output. In fact, I built the first demo from the second, using the info that was sent through the module to "convert" the transaction. However, when I tried to convert the other programs from the LWP::UserAgent form of transaction to the SOAP::Lite form, I failed miserabely.<br>
Looking at the SOAP::Lite module in CPAN, I haven't been able to find explanations about how to create a SOAP request like my predacessor did(e.g. how do you know what the soap action is). My questions are (and again, sorry for the length): <br>
1) When should I use the LWP::UserAgent, and when should I use SOAP::Lite? <br>
2) When using SOAP::Lite, how and when can I build the SOAP content from scratch. What should I use for the SAOP action (In my demo it was the uri with a prefix, but is that the how its done all the time)? <br>
3) What advantages does SOAP::WSDL give me over SOAP::Lite. Is it more recommended? <br>
<br>
Any links to examples and info sites will be greatly appreciated.<br>
Thanks a lot<br>
Guy Naamati (mrguy123)
<br><br>
<i>The rain it raineth on the just,
and also on the unjust fella, <br>
But chiefly on the just, because
the unjust steals the just's umbrella.</i><br>
-- Lord Bowen
<p><small>2006-07-19 Retitled by [holli], as per Monastery [id://341118|guidelines] <br />Original title: 'SOAP::Lite vs LWP::UserAgent for SOAP transcations'</small></p>