Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi monks, I apologize in advance for the length of this one:
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  http://www.imdb.com/finds=all&q=cats 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):
#!/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/Sea +rchRetrieve"; my $content = '<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Env +elope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOA +P-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="htt +p://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/ +1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/so +ap/encoding/"><SOAP-ENV:Body><namesp1:search xmlns:namesp1="http://wo +k-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="x +sd: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,$conten +t); 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"; }
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:
#!/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/SearchRet +rieve?wsdl"); $soap_request->proxy("http://wok-ws.isiknowledge.com/esti/soap/SearchR +etrieve"); $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'), );
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.
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):
1) When should I use the LWP::UserAgent, and when should I use SOAP::Lite?
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)?
3) What advantages does SOAP::WSDL give me over SOAP::Lite. Is it more recommended?

Any links to examples and info sites will be greatly appreciated.
Thanks a lot
Guy Naamati (mrguy123)

The rain it raineth on the just, and also on the unjust fella,
But chiefly on the just, because the unjust steals the just's umbrella.

-- Lord Bowen

2006-07-19 Retitled by holli, as per Monastery guidelines
Original title: 'SOAP::Lite vs LWP::UserAgent for SOAP transcations'


In reply to SOAP::Lite vs LWP::UserAgent for SOAP transactions by mrguy123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2022-08-17 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?