<?xml version="1.0" encoding="windows-1252"?>
<node id="91732" title="SOAP::Lite" created="2001-06-26 19:54:49" updated="2005-08-13 22:46:32">
<type id="31663">
modulereview</type>
<author id="34584">
$code or die</author>
<data>
<field name="doctext">
&lt;p&gt;&lt;b&gt;Update: &lt;/b&gt;Please let me know if the &amp;lt;pre&amp;gt; tags bother you. I wrote this in pod. I'll try and convert it to code tags if you think it's necessary.&lt;/p&gt;
&lt;H2&gt;&lt;A NAME="soap"&gt;SOAP&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;(Simple Object Access Protocol : &lt;A HREF="http://www.w3.org/TR/SOAP/"&gt;http://www.w3.org/TR/SOAP/&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;SOAP is a lightweight protocol for exchanging data using XML. It allows you
access methods and properties of remote objects. Each method call is typically
a seperate SOAP envelope (xml document). The SOAP server opens the envelope,
processes the data, and returns an envelope to the client with a response.&lt;/P&gt;
&lt;P&gt;SOAP::Lite does the hard work (creating the envelopes and decoding them), leaving
the developer the easy task or writing client and server code which is almost no
different to what she would have written before.&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="why use soap::lite"&gt;Why use SOAP::Lite&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;* It's much easier that using &lt;CODE&gt;SOAP&lt;/CODE&gt; where you have to do a lot of the hard work as well&lt;/P&gt;
&lt;P&gt;* It supports SOAP 1.1&lt;/P&gt;
&lt;P&gt;* It supports lots of protocols other than HTTP. You can even create your own SOAP daemon&lt;/P&gt;
&lt;P&gt;* It supports WSDL (Web Service Description Language)&lt;/P&gt;
&lt;P&gt;* It supports tracing - so you can see what's going on behind the scenes&lt;/P&gt;
&lt;P&gt;* You can use the COM interface on Windows machines&lt;/P&gt;
&lt;P&gt;* It's very well documented&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="why not use soap::lite"&gt;Why NOT use SOAP::Lite&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;* You want a more low-level API - and more work&lt;/P&gt;
&lt;P&gt;* SOAP can be slower that methods you may already be using&lt;/P&gt;
&lt;P&gt;* You prefer shower gel&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="simple calculator soap server"&gt;Simple Calculator SOAP Server&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;The SOAP server is a regular Perl script, which instructs SOAP::Lite to dispatch methods to 
a named package. My example uses SOAP::Lite's CGI implimentation, but you can use SOAP::Lite
over many other protocols such as POP3, SMTP and FTP.&lt;/P&gt;
&lt;PRE&gt;
  use strict;
  use SOAP::Transport::HTTP;
  SOAP::Transport::HTTP::CGI   
    -&amp;gt; dispatch_to('My::SoapServer')
    -&amp;gt; handle;&lt;/PRE&gt;
&lt;PRE&gt;
  package My::SoapServer;&lt;/PRE&gt;
&lt;PRE&gt;
  sub add      { $_&amp;#091;1&amp;#093; + $_&amp;#091;2&amp;#093;; }
  sub subtract { $_&amp;#091;1&amp;#093; - $_&amp;#091;2&amp;#093;; }
  sub multiply { $_&amp;#091;1&amp;#093; * $_&amp;#091;2&amp;#093;; }
  sub divide   { $_&amp;#091;1&amp;#093; / $_&amp;#091;2&amp;#093;; }&lt;/PRE&gt;
&lt;P&gt;Note that I am ignoring the first parameter for each of the method calls since it is simply the package name.
I guess that SOAP::Lite interprets your requests as (in this case): &lt;CODE&gt;My::SoapServer-&lt;/CODE&gt;&amp;gt;&lt;CODE&gt;methodname&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="client code to access this web service"&gt;Client Code to access this Web Service&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;The client code is quite straightforward. You create a SOAP::lite object, 
passing it the details on the SOAP service. Then for each method call, it
returns an object which has, amongst others, &lt;CODE&gt;result&lt;/CODE&gt; and &lt;CODE&gt;fault&lt;/CODE&gt; methods.&lt;/P&gt;
&lt;PRE&gt;
  use strict;
  use SOAP::Lite;
  my $soap = SOAP::Lite
    -&amp;gt;uri(&amp;quot;http://myserver.org/My::SoapServer&amp;quot;)
    -&amp;gt;proxy(&amp;quot;http://www.mywebserver.com/soapserver.pl&amp;quot;);
&lt;/PRE&gt;
&lt;PRE&gt;

  print $soap-&amp;gt;add(16,8)-&amp;gt;result,       &amp;quot;\n&amp;quot;;
  print $soap-&amp;gt;subtract(10,2)-&amp;gt;result,  &amp;quot;\n&amp;quot;;
  print $soap-&amp;gt;multiply(5,5)-&amp;gt;result,   &amp;quot;\n&amp;quot;;
  print $soap-&amp;gt;divide(1024,2)-&amp;gt;result,  &amp;quot;\n&amp;quot;;&lt;/PRE&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="catching errors"&gt;Catching Errors&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;Suppose I misspell the method call (ADD instead of add):&lt;/P&gt;
&lt;PRE&gt;
  print $soap-&amp;gt;ADD(16,8)-&amp;gt;result;&lt;/PRE&gt;
&lt;P&gt;...prints nothing. Not very helpful. However, if you do the following, you can print the fault, (if there is one)...&lt;/P&gt;
&lt;PRE&gt;
  my $res = $soap-&amp;gt;ADD(16,10);
  if ($res-&amp;gt;fault) {
    print $res-&amp;gt;faultstring;
  } else {
    print $res-&amp;gt;result;
  }&lt;/PRE&gt;
&lt;P&gt;And this time, it will print ``&lt;CODE&gt;Bad Method Call&lt;/CODE&gt;''&lt;/P&gt;
&lt;P&gt;There are many more error handling functions provided by SOAP::Lite. But you'll need to read the documentation!&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="autodispatching"&gt;Autodispatching&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;So far, the client code all looks a bit un-friendly. SOAP::Lite has a feature called &lt;CODE&gt;autodispatch&lt;/CODE&gt;
which allows you to write your client code just the same way you would write it if My::SoapServer were
a locally installed module. e.g.&lt;/P&gt;
&lt;PRE&gt;
  print add(100,-99);&lt;/PRE&gt;
&lt;P&gt;See the SOAP::Lite docs for more information and unexpected side-effects.&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="things to note"&gt;Things to note&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;See the documentation on &lt;CODE&gt;autodispatch&lt;/CODE&gt; before you use it - or it might have strange side-efects. (It overloads UNIVERSAL::AUTOLOAD)&lt;/P&gt;
&lt;P&gt;See the documentation on performance - you may be able to improve performance by base64 encoding the XML;&lt;/P&gt;
&lt;P&gt;
&lt;H2&gt;&lt;A NAME="useful links"&gt;Useful Links&lt;/A&gt;&lt;/H2&gt;
&lt;P&gt;There is a two part article on perl.com by Paul Kulchenko (SOAP::Lite author):&lt;/P&gt;
&lt;P&gt;Part 1: &lt;A HREF="http://www.perl.com/pub/2001/01/soap.html"&gt;http://www.perl.com/pub/2001/01/soap.html&lt;/A&gt;&lt;BR&gt;
Part 2: &lt;A HREF="http://www.perl.com/pub/2001/04/24/soap.html"&gt;http://www.perl.com/pub/2001/04/24/soap.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;and you can visit Paul's site at the aptly named &lt;A HREF="http://www.soaplite.com,"&gt;http://www.soaplite.com,&lt;/A&gt; which is an excellent
SOAP resource in itself&lt;/P&gt;
&lt;p&gt;&lt;b&gt;Update 2:&lt;/B&gt; &lt;a href="http://www.salcentral.com"&gt;http://www.salcentral.com&lt;/a&gt; and &lt;a href="http://www.xmethods.net"&gt;http://www.xmethods.net&lt;/a&gt; both provide listings of Web Services you can 
play around with.&lt;/p&gt;
</field>
<field name="itemdescription">
Add SOAP capabilities to your applications with ease</field>
<field name="usercomment">
</field>
<field name="identifier">
</field>
</data>
</node>
