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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
<!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.4. Debugging SOAP Web Services</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="first_steps.html" title="12.3. First Steps with SOAP">
<link rel="next" href="wsdl.html" title="12.5. Introducing WSDL">
</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">Debugging SOAP Web Services</span></td>
<td id="navigation" align="right" valign="top"> <a href="first_steps.html" title="Prev: “First Steps with SOAP”"><<</a> <a href="wsdl.html" title="Next: “Introducing WSDL”">>></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.debug"></a>12.4. Debugging <span class="acronym">SOAP</span> Web Services
</h2>
</div>
</div>
<div></div>
</div>
<div class="abstract">
<p>The <span class="acronym">SOAP</span> libraries provide an easy way to see what's going on behind the scenes.
</p>
</div>
<p>Turning on debugging is a simple matter of setting two flags in the <tt class="classname">SOAPProxy</tt>'s configuration.
</p>
<div class="example"><a name="d0e30423"></a><h3 class="title">Example 12.7. Debugging <span class="acronym">SOAP</span> Web Services
</h3><pre class="screen">
<tt class="prompt">>>> </tt><span class="userinput"><span class='pykeyword'>from</span> SOAPpy <span class='pykeyword'>import</span> SOAPProxy</span>
<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">n = <span class='pystring'>'urn:xmethods-Temperature'</span></span>
<tt class="prompt">>>> </tt><span class="userinput">server = SOAPProxy(url, namespace=n)</span> <a name="soap.debug.1.1"></a><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12">
<tt class="prompt">>>> </tt><span class="userinput">server.config.dumpSOAPOut = 1</span> <a name="soap.debug.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.config.dumpSOAPIn = 1</span>
<tt class="prompt">>>> </tt><span class="userinput">temperature = server.getTemp(<span class='pystring'>'27502'</span>)</span> <a name="soap.debug.1.3"></a><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12">
<span class="computeroutput">*** Outgoing SOAP ******************************************************
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getTemp xmlns:ns1="urn:xmethods-Temperature" SOAP-ENC:root="1">
<v1 xsi:type="xsd:string">27502</v1>
</ns1:getTemp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************************************************************************
*** Incoming SOAP ******************************************************
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:getTempResponse xmlns:ns1="urn:xmethods-Temperature"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:float">80.0</return>
</ns1:getTempResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
************************************************************************
</span>
<tt class="prompt">>>> </tt><span class="userinput">temperature</span>
<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.debug.1.1"><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">First, create the <tt class="classname">SOAPProxy</tt> like normal, with the service <span class="acronym">URL</span> and the namespace.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.1.2"><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">Second, turn on debugging by setting <tt class="varname">server.config.dumpSOAPIn</tt> and <tt class="varname">server.config.dumpSOAPOut</tt>.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.1.3"><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">Third, call the remote <span class="acronym">SOAP</span> method as usual. The <span class="acronym">SOAP</span> library will print out both the outgoing XML request document, and the incoming XML response document. This is all the hard
work that <tt class="classname">SOAPProxy</tt> is doing for you. Intimidating, isn't it? Let's break it down.
</td>
</tr>
</table>
</div>
</div>
<p>Most of the XML request document that gets sent to the server is just boilerplate. Ignore all the namespace declarations;
they're going to be the same (or similar) for all <span class="acronym">SOAP</span> calls. The heart of the “<span class="quote">function call</span>” is this fragment within the <tt class="sgmltag-element"><Body></tt> element:
</p>
<div class="informalexample"><pre class="programlisting">
<ns1:getTemp <a name="soap.debug.2.1"></a><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12">
xmlns:ns1=<span class='pystring'>"urn:xmethods-Temperature"</span> <a name="soap.debug.2.2"></a><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12">
SOAP-ENC:root=<span class='pystring'>"1"</span>>
<v1 xsi:type=<span class='pystring'>"xsd:string"</span>>27502</v1> <a name="soap.debug.2.3"></a><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12">
</ns1:getTemp>
</pre><div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.2.1"><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">The element name is the function name, <tt class="function">getTemp</tt>. <tt class="classname">SOAPProxy</tt> uses <a href="../scripts_and_streams/handlers_by_node_type.html" title="10.5. Creating separate handlers by node type"><tt class="function">getattr</tt> as a dispatcher</a>. Instead of calling separate local methods based on the method name, it actually uses the method name to construct the XML
request document.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.2.2"><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">The function's XML element is contained in a specific namespace, which is the namespace you specified when you created the
<tt class="classname">SOAPProxy</tt> object. Don't worry about the <tt class="literal">SOAP-ENC:root</tt>; that's boilerplate too.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.2.3"><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">The arguments of the function also got translated into XML. <tt class="classname">SOAPProxy</tt> introspects each argument to determine its datatype (in this case it's a string). The argument datatype goes into the <tt class="literal">xsi:type</tt> attribute, followed by the actual string value.
</td>
</tr>
</table>
</div>
</div>
<p>The XML return document is equally easy to understand, once you know what to ignore. Focus on this fragment within the <tt class="sgmltag-element"><Body></tt>:
</p>
<div class="informalexample"><pre class="programlisting">
<ns1:getTempResponse <a name="soap.debug.3.1"></a><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12">
xmlns:ns1=<span class='pystring'>"urn:xmethods-Temperature"</span> <a name="soap.debug.3.2"></a><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12">
SOAP-ENV:encodingStyle=<span class='pystring'>"http://schemas.xmlsoap.org/soap/encoding/"</span>>
<<span class='pykeyword'>return</span> xsi:type=<span class='pystring'>"xsd:float"</span>>80.0</<span class='pykeyword'>return</span>> <a name="soap.debug.3.3"></a><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12">
</ns1:getTempResponse>
</pre><div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.3.1"><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">The server wraps the function return value within a <tt class="sgmltag-element"><getTempResponse></tt> element. By convention, this wrapper element is the name of the function, plus <tt class="literal">Response</tt>. But it could really be almost anything; the important thing that <tt class="classname">SOAPProxy</tt> notices is not the element name, but the namespace.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.3.2"><img src="../images/callouts/2.png" alt="2" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">The server returns the response in the same namespace we used in the request, the same namespace we specified when we first
create the <tt class="classname">SOAPProxy</tt>. Later in this chapter we'll see what happens if you forget to specify the namespace when creating the <tt class="classname">SOAPProxy</tt>.
</td>
</tr>
<tr>
<td width="12" valign="top" align="left"><a href="#soap.debug.3.3"><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12"></a>
</td>
<td valign="top" align="left">The return value is specified, along with its datatype (it's a float). <tt class="classname">SOAPProxy</tt> uses this explicit datatype to create a <span class="application">Python</span> object of the correct native datatype and return it.
</td>
</tr>
</table>
</div>
</div>
</div>
<table class="Footer" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
<tr>
<td width="35%" align="left"><br><a class="NavigationArrow" href="first_steps.html"><< First Steps with SOAP</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> <a href="first_steps.html" title="12.3. First Steps with SOAP">3</a> <span class="divider">|</span> <span class="thispage">4</span> <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="wsdl.html">Introducing WSDL >></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>
|