1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>12.3. First Steps with SOAP</title>
<link rel="stylesheet" href="../diveintopython.css" type="text/css">
<link rev="made" href="mailto:f8dy@diveintopython.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.52.2">
<meta name="keywords" content="Python, Dive Into Python, tutorial, object-oriented, programming, documentation, book, free">
<meta name="description" content="Python from novice to pro">
<link rel="home" href="../toc/index.html" title="Dive Into Python">
<link rel="up" href="index.html" title="Chapter 12. SOAP Web Services">
<link rel="previous" href="install.html" title="12.2. Installing the SOAP Libraries">
<link rel="next" href="debugging.html" title="12.4. Debugging SOAP Web Services">
</head>
<body>
<table id="Header" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td id="breadcrumb" colspan="5" align="left" valign="top">You are here: <a href="../index.html">Home</a> > <a href="../toc/index.html">Dive Into Python</a> > <a href="index.html">SOAP Web Services</a> > <span class="thispage">First Steps with SOAP</span></td>
<td id="navigation" align="right" valign="top"> <a href="install.html" title="Prev: “Installing the SOAP Libraries”"><<</a> <a href="debugging.html" title="Next: “Debugging SOAP Web Services”">>></a></td>
</tr>
<tr>
<td colspan="3" id="logocontainer">
<h1 id="logo"><a href="../index.html" accesskey="1">Dive Into Python</a></h1>
<p id="tagline">Python from novice to pro</p>
</td>
<td colspan="3" align="right">
<form id="search" method="GET" action="http://www.google.com/custom">
<p><label for="q" accesskey="4">Find: </label><input type="text" id="q" name="q" size="20" maxlength="255" value=" "> <input type="submit" value="Search"><input type="hidden" name="cof" value="LW:752;L:http://diveintopython.org/images/diveintopython.png;LH:42;AH:left;GL:0;AWFID:3ced2bb1f7f1b212;"><input type="hidden" name="domains" value="diveintopython.org"><input type="hidden" name="sitesearch" value="diveintopython.org"></p>
</form>
</td>
</tr>
</table>
<!--#include virtual="/inc/ads" -->
<div class="section" lang="en">
<div class="titlepage">
<div>
<div>
<h2 class="title"><a name="soap.firststeps"></a>12.3. First Steps with <span class="acronym">SOAP</span></h2>
</div>
</div>
<div></div>
</div>
<div class="abstract">
<p>The heart of <span class="acronym">SOAP</span> is the ability to call remote functions. There are a number of public access <span class="acronym">SOAP</span> servers that provide simple functions for demonstration purposes.
</p>
</div>
<p>The most popular public access <span class="acronym">SOAP</span> server is <a href="http://www.xmethods.net/">http://www.xmethods.net/</a>. This example uses a demonstration function that takes a United States zip code and returns the current temperature in that
region.
</p>
<div class="example"><a name="d0e30286"></a><h3 class="title">Example 12.6. Getting the Current Temperature</h3><pre class="screen">
<tt class="prompt">>>> </tt><span class="userinput"><span class='pykeyword'>from</span> SOAPpy <span class='pykeyword'>import</span> SOAPProxy</span> <a name="soap.firststeps.1.1"></a><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12">
<tt class="prompt">>>> </tt><span class="userinput">url = <span class='pystring'>'http://services.xmethods.net:80/soap/servlet/rpcrouter'</span></span>
<tt class="prompt">>>> </tt><span class="userinput">namespace = <span class='pystring'>'urn:xmethods-Temperature'</span></span> <a name="soap.firststeps.1.2"></a><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12">
<tt class="prompt">>>> </tt><span class="userinput">server = SOAPProxy(url, namespace)</span> <a name="soap.firststeps.1.3"></a><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12">
<tt class="prompt">>>> </tt><span class="userinput">server.getTemp(<span class='pystring'>'27502'</span>)</span> <a name="soap.firststeps.1.4"></a><img src="../images/callouts/4.png" alt="4" border="0" width="12" height="12">
<span class="computeroutput">80.0</span>
</pre><div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td width="12" valign="top" align="left"><a href="#soap.firststeps.1.1"><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">You access the remote <span class="acronym">SOAP</span> server through a proxy class, <tt class="classname">SOAPProxy</tt>. The proxy handles all the internals of <span class="acronym">SOAP</span> for you, including creating the XML request document out of the function name and argument list, sending the request over
HTTP to the remote <span class="acronym">SOAP</span> server, parsing the XML response document, and creating native <span class="application">Python</span> values to return. You'll see what these XML documents look like in the next section.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.firststeps.1.2"><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">Every <span class="acronym">SOAP</span> service has a <span class="acronym">URL</span> which handles all the requests. The same <span class="acronym">URL</span> is used for all function calls. This particular service only has a single function, but later in this chapter you'll see
examples of the Google <span class="acronym">API</span>, which has several functions. The service <span class="acronym">URL</span> is shared by all functions.Each <span class="acronym">SOAP</span> service also has a namespace, which is defined by the server and is completely arbitrary. It's simply part of the configuration
required to call <span class="acronym">SOAP</span> methods. It allows the server to share a single service <span class="acronym">URL</span> and route requests between several unrelated services. It's like dividing <span class="application">Python</span> modules into <a href="../xml_processing/packages.html" title="9.2. Packages">packages</a>.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.firststeps.1.3"><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">You're creating the <tt class="classname">SOAPProxy</tt> with the service <span class="acronym">URL</span> and the service namespace. This doesn't make any connection to the <span class="acronym">SOAP</span> server; it simply creates a local <span class="application">Python</span> object.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.firststeps.1.4"><img src="../images/callouts/4.png" alt="4" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">Now with everything configured properly, you can actually call remote <span class="acronym">SOAP</span> methods as if they were local functions. You pass arguments just like a normal function, and you get a return value just
like a normal function. But under the covers, there's a heck of a lot going on.
</td>
</tr>
</table>
</div>
</div>
<p>Let's peek under those covers.</p>
</div>
<table class="Footer" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td width="35%" align="left"><br><a class="NavigationArrow" href="install.html"><< Installing the SOAP Libraries</a></td>
<td width="30%" align="center"><br> <span class="divider">|</span> <a href="index.html#soap.divein" title="12.1. Diving In">1</a> <span class="divider">|</span> <a href="install.html" title="12.2. Installing the SOAP Libraries">2</a> <span class="divider">|</span> <span class="thispage">3</span> <span class="divider">|</span> <a href="debugging.html" title="12.4. Debugging SOAP Web Services">4</a> <span class="divider">|</span> <a href="wsdl.html" title="12.5. Introducing WSDL">5</a> <span class="divider">|</span> <a href="introspection.html" title="12.6. Introspecting SOAP Web Services with WSDL">6</a> <span class="divider">|</span> <a href="google.html" title="12.7. Searching Google">7</a> <span class="divider">|</span> <a href="troubleshooting.html" title="12.8. Troubleshooting SOAP Web Services">8</a> <span class="divider">|</span> <a href="summary.html" title="12.9. Summary">9</a> <span class="divider">|</span>
</td>
<td width="35%" align="right"><br><a class="NavigationArrow" href="debugging.html">Debugging SOAP Web Services >></a></td>
</tr>
<tr>
<td colspan="3"><br></td>
</tr>
</table>
<div class="Footer">
<p class="copyright">Copyright © 2000, 2001, 2002, 2003, 2004 <a href="mailto:mark@diveintopython.org">Mark Pilgrim</a></p>
</div>
</body>
</html>
|