root/docs/bobchin/diveintopython/soap_web_services/debugging.html @ 26131

Revision 26131, 16.4 kB (checked in by drry, 4 years ago)
  • added subversion properties.
  • Property svn:mime-type set to text/html
Line 
1
2<!DOCTYPE html
3  PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4<html>
5   <head>
6      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
7   
8      <title>12.4.&nbsp;Debugging SOAP Web Services</title>
9      <link rel="stylesheet" href="../diveintopython.css" type="text/css">
10      <link rev="made" href="mailto:f8dy@diveintopython.org">
11      <meta name="generator" content="DocBook XSL Stylesheets V1.52.2">
12      <meta name="keywords" content="Python, Dive Into Python, tutorial, object-oriented, programming, documentation, book, free">
13      <meta name="description" content="Python from novice to pro">
14      <link rel="home" href="../toc/index.html" title="Dive Into Python">
15      <link rel="up" href="index.html" title="Chapter&nbsp;12.&nbsp;SOAP Web Services">
16      <link rel="previous" href="first_steps.html" title="12.3.&nbsp;First Steps with SOAP">
17      <link rel="next" href="wsdl.html" title="12.5.&nbsp;Introducing WSDL">
18   </head>
19   <body>
20      <table id="Header" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
21         <tr>
22            <td id="breadcrumb" colspan="5" align="left" valign="top">You are here: <a href="../index.html">Home</a>&nbsp;&gt;&nbsp;<a href="../toc/index.html">Dive Into Python</a>&nbsp;&gt;&nbsp;<a href="index.html">SOAP Web Services</a>&nbsp;&gt;&nbsp;<span class="thispage">Debugging SOAP Web Services</span></td>
23            <td id="navigation" align="right" valign="top">&nbsp;&nbsp;&nbsp;<a href="first_steps.html" title="Prev: &#8220;First Steps with SOAP&#8221;">&lt;&lt;</a>&nbsp;&nbsp;&nbsp;<a href="wsdl.html" title="Next: &#8220;Introducing WSDL&#8221;">&gt;&gt;</a></td>
24         </tr>
25         <tr>
26            <td colspan="3" id="logocontainer">
27               <h1 id="logo"><a href="../index.html" accesskey="1">Dive Into Python</a></h1>
28               <p id="tagline">Python from novice to pro</p>
29            </td>
30            <td colspan="3" align="right">
31               <form id="search" method="GET" action="http://www.google.com/custom">
32                  <p><label for="q" accesskey="4">Find:&nbsp;</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>
33               </form>
34            </td>
35         </tr>
36      </table>
37      <div id="sponsoredlinks">
38<script type="text/javascript"><!--
39google_ad_client = "pub-7176621954566026";
40google_ad_width = 120;
41google_ad_height = 600;
42google_ad_format = "120x600_as";
43google_color_border = "800000";
44google_color_bg = "FFFFFF";
45google_color_link = "800000";
46google_color_url = "008000";
47google_color_text = "000000";
48google_ad_channel ="1280308639";
49//--></script>
50<script type="text/javascript"
51  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
52</script>
53</div>
54
55      <div class="section" lang="en">
56         <div class="titlepage">
57            <div>
58               <div>
59                  <h2 class="title"><a name="soap.debug"></a>12.4.&nbsp;Debugging <span class="acronym">SOAP</span> Web Services
60                  </h2>
61               </div>
62            </div>
63            <div></div>
64         </div>
65         <div class="abstract">
66            <p>The <span class="acronym">SOAP</span> libraries provide an easy way to see what's going on behind the scenes.
67            </p>
68         </div>
69         <p>Turning on debugging is a simple matter of setting two flags in the <tt class="classname">SOAPProxy</tt>'s configuration.
70         </p>
71         <div class="example"><a name="d0e30423"></a><h3 class="title">Example&nbsp;12.7.&nbsp;Debugging <span class="acronym">SOAP</span> Web Services
72            </h3><pre class="screen">
73<tt class="prompt">&gt;&gt;&gt; </tt><span class="userinput"><span class='pykeyword'>from</span> SOAPpy <span class='pykeyword'>import</span> SOAPProxy</span>
74<tt class="prompt">&gt;&gt;&gt; </tt><span class="userinput">url = <span class='pystring'>'http://services.xmethods.net:80/soap/servlet/rpcrouter'</span></span>
75<tt class="prompt">&gt;&gt;&gt; </tt><span class="userinput">n = <span class='pystring'>'urn:xmethods-Temperature'</span></span>
76<tt class="prompt">&gt;&gt;&gt; </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">
77<tt class="prompt">&gt;&gt;&gt; </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">
78<tt class="prompt">&gt;&gt;&gt; </tt><span class="userinput">server.config.dumpSOAPIn = 1</span>
79<tt class="prompt">&gt;&gt;&gt; </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">
80<span class="computeroutput">*** Outgoing SOAP ******************************************************
81&lt;?xml version="1.0" encoding="UTF-8"?&gt;
82&lt;SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
83  xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
84  xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
85  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
86  xmlns:xsd="http://www.w3.org/1999/XMLSchema"&gt;
87&lt;SOAP-ENV:Body&gt;
88&lt;ns1:getTemp xmlns:ns1="urn:xmethods-Temperature" SOAP-ENC:root="1"&gt;
89&lt;v1 xsi:type="xsd:string"&gt;27502&lt;/v1&gt;
90&lt;/ns1:getTemp&gt;
91&lt;/SOAP-ENV:Body&gt;
92&lt;/SOAP-ENV:Envelope&gt;
93************************************************************************
94*** Incoming SOAP ******************************************************
95&lt;?xml version='1.0' encoding='UTF-8'?&gt;
96&lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
97  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
98  xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
99&lt;SOAP-ENV:Body&gt;
100&lt;ns1:getTempResponse xmlns:ns1="urn:xmethods-Temperature"
101  SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;
102&lt;return xsi:type="xsd:float"&gt;80.0&lt;/return&gt;
103&lt;/ns1:getTempResponse&gt;
104
105&lt;/SOAP-ENV:Body&gt;
106&lt;/SOAP-ENV:Envelope&gt;
107************************************************************************
108</span>
109<tt class="prompt">&gt;&gt;&gt; </tt><span class="userinput">temperature</span>
110<span class="computeroutput">80.0</span>
111</pre><div class="calloutlist">
112               <table border="0" summary="Callout list">
113                  <tr>
114                     <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>
115                     </td>
116                     <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.
117                     </td>
118                  </tr>
119                  <tr>
120                     <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>
121                     </td>
122                     <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>.
123                     </td>
124                  </tr>
125                  <tr>
126                     <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>
127                     </td>
128                     <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
129                        work that <tt class="classname">SOAPProxy</tt> is doing for you.  Intimidating, isn't it?  Let's break it down.
130                     </td>
131                  </tr>
132               </table>
133            </div>
134         </div>
135         <p>Most of the XML request document that gets sent to the server is just boilerplate.  Ignore all the namespace declarations;
136            they're going to be the same (or similar) for all <span class="acronym">SOAP</span> calls.  The heart of the &#8220;<span class="quote">function call</span>&#8221; is this fragment within the <tt class="sgmltag-element">&lt;Body&gt;</tt> element:
137         </p>
138         <div class="informalexample"><pre class="programlisting">
139&lt;ns1:getTemp                                 <a name="soap.debug.2.1"></a><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12">
140  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">
141  SOAP-ENC:root=<span class='pystring'>"1"</span>&gt;
142&lt;v1 xsi:type=<span class='pystring'>"xsd:string"</span>&gt;27502&lt;/v1&gt;         <a name="soap.debug.2.3"></a><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12">
143&lt;/ns1:getTemp&gt;
144</pre><div class="calloutlist">
145               <table border="0" summary="Callout list">
146                  <tr>
147                     <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>
148                     </td>
149                     <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.&nbsp;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
150                        request document.
151                     </td>
152                  </tr>
153                  <tr>
154                     <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>
155                     </td>
156                     <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
157                        <tt class="classname">SOAPProxy</tt> object.  Don't worry about the <tt class="literal">SOAP-ENC:root</tt>; that's boilerplate too.
158                     </td>
159                  </tr>
160                  <tr>
161                     <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>
162                     </td>
163                     <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.
164                     </td>
165                  </tr>
166               </table>
167            </div>
168         </div>
169         <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">&lt;Body&gt;</tt>:
170         </p>
171         <div class="informalexample"><pre class="programlisting">
172&lt;ns1:getTempResponse                             <a name="soap.debug.3.1"></a><img src="../images/callouts/1.png" alt="1" border="0" width="12" height="12">
173  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">
174  SOAP-ENV:encodingStyle=<span class='pystring'>"http://schemas.xmlsoap.org/soap/encoding/"</span>&gt;
175&lt;<span class='pykeyword'>return</span> xsi:type=<span class='pystring'>"xsd:float"</span>&gt;80.0&lt;/<span class='pykeyword'>return</span>&gt;       <a name="soap.debug.3.3"></a><img src="../images/callouts/3.png" alt="3" border="0" width="12" height="12">
176&lt;/ns1:getTempResponse&gt;
177</pre><div class="calloutlist">
178               <table border="0" summary="Callout list">
179                  <tr>
180                     <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>
181                     </td>
182                     <td valign="top" align="left">The server wraps the function return value within a <tt class="sgmltag-element">&lt;getTempResponse&gt;</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.
183                     </td>
184                  </tr>
185                  <tr>
186                     <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>
187                     </td>
188                     <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
189                        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>.
190                     </td>
191                  </tr>
192                  <tr>
193                     <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>
194                     </td>
195                     <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.
196                     </td>
197                  </tr>
198               </table>
199            </div>
200         </div>
201      </div>
202      <table class="Footer" width="100%" border="0" cellpadding="0" cellspacing="0" summary="">
203         <tr>
204            <td width="35%" align="left"><br><a class="NavigationArrow" href="first_steps.html">&lt;&lt;&nbsp;First Steps with SOAP</a></td>
205            <td width="30%" align="center"><br>&nbsp;<span class="divider">|</span>&nbsp;<a href="index.html#soap.divein" title="12.1.&nbsp;Diving In">1</a> <span class="divider">|</span> <a href="install.html" title="12.2.&nbsp;Installing the SOAP Libraries">2</a> <span class="divider">|</span> <a href="first_steps.html" title="12.3.&nbsp;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.&nbsp;Introducing WSDL">5</a> <span class="divider">|</span> <a href="introspection.html" title="12.6.&nbsp;Introspecting SOAP Web Services with WSDL">6</a> <span class="divider">|</span> <a href="google.html" title="12.7.&nbsp;Searching Google">7</a> <span class="divider">|</span> <a href="troubleshooting.html" title="12.8.&nbsp;Troubleshooting SOAP Web Services">8</a> <span class="divider">|</span> <a href="summary.html" title="12.9.&nbsp;Summary">9</a>&nbsp;<span class="divider">|</span>&nbsp;
206            </td>
207            <td width="35%" align="right"><br><a class="NavigationArrow" href="wsdl.html">Introducing WSDL&nbsp;&gt;&gt;</a></td>
208         </tr>
209         <tr>
210            <td colspan="3"><br></td>
211         </tr>
212      </table>
213      <div class="Footer">
214         <p class="copyright">Copyright &copy; 2000, 2001, 2002, 2003, 2004 <a href="mailto:mark@diveintopython.org">Mark Pilgrim</a></p>
215      </div>
216   </body>
217</html>
Note: See TracBrowser for help on using the browser.