[ZF-10089] Zend_Log
[zend.git] / documentation / manual / es / module_specs / Zend_XmlRpc_Client.xml
blobb57ce8b2cc382838b3015b4b1765205aa5e13650
1 <?xml version="1.0" encoding="UTF-8"?>
2     <!-- EN-Revision: 20794 -->
3     <!-- Reviewed: no -->
4 <sect1 id="zend.xmlrpc.client">
5     <title>Zend_XmlRpc_Client</title>
7     <sect2 id="zend.xmlrpc.client.introduction">
8         <title>Introdución</title>
10         <para>
11             Zend Framework provee soporte para consumo remoto para servicios
12             <acronym>XML-RPC</acronym>
13             como un cliente en el paquete
14             <classname>Zend_XmlRpc_Client</classname>
15             . Su mejor
16             característica es la conversión automática de tipos entre
17             <acronym>PHP</acronym>
18             y
19             <acronym>XML-RPC</acronym>
20             , un servidor
21             de objeto proxy, y acceso a capacidades de instrospección del
22             servidor.
23         </para>
25     </sect2>
27     <sect2 id="zend.xmlrpc.client.method-calls">
28         <title>Method Calls</title>
30         <para>
31             El constructor de
32             <classname>Zend_XmlRpc_Client</classname>
33             recibe la
34             <acronym>URL</acronym>
35             del servidor
36             <acronym>XML-RPC</acronym>
37             como su primer parámetro. La nueva
38             instacia devuelta puede ser usada para llamar
39             cualquier número de
40             métodos remotos en el punto final.
41         </para>
43         <para>
44             Para llamar un método remoto con el cliente
45             <acronym>XML-RPC</acronym>
46             , instáncealo y usa el método de
47             instancia
48             <methodname>call()</methodname>
49             . El código de ejemplo a
50             continuación utiliza una demostración en el servidor
51             <acronym>XML-RPC</acronym>
52             en el sitio web de Zend Framework .
53             Puede utilizarlo para probar o explorar los
54             componentes
55             <classname>Zend_XmlRpc</classname>
56             .
57         </para>
59         <example id="zend.xmlrpc.client.method-calls.example-1">
60             <title>XML-RPC Method Call</title>
61             <programlisting language="php"><![CDATA[
62 $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
64 echo $client->call('test.sayHello');
66 // hello
67 ]]></programlisting>
68         </example>
70         <para>
71             El valor
72             <acronym>XML-RPC</acronym>
73             devuelto desde la llamada al
74             método remoto automáticamente será convertida al tipo nativo
75             <acronym>PHP</acronym>
76             equivalente . En el ejemplo anterior, es
77             devuelto un
78             <type>string</type>
79             <acronym>PHP</acronym>
80             y está listo para ser usado inmediatamente.
81         </para>
83         <para>
84             El primer parámetro del método
85             <methodname>call()</methodname>
86             recibe el nombre del método remoto que llamar. Si el método remoto
87             requiere algún
88             parámetro, éste puede ser enviado por el suministro
89             de un segundo, parámetro opcional a
90             <methodname>call()</methodname>
91             con un
92             <type>array</type>
93             de valores para pasar el
94             método remoto:
95         </para>
97         <example id="zend.xmlrpc.client.method-calls.example-2">
98             <title>XML-RPC Method Call with Parameters</title>
99             <programlisting language="php"><![CDATA[
100 $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
102 $arg1 = 1.1;
103 $arg2 = 'foo';
105 $result = $client->call('test.sayHello', array($arg1, $arg2));
107 // $result es un tipo nativo PHP
108 ]]></programlisting>
109         </example>
111         <para>
112             si el método remoto no requiere parámetros, este parámetro
113             opcional podrá ser excluido o
114             se puede pasar un
115             <methodname>array()</methodname>
116             vacío. El array de parámeters
117             para el método repoto puede contener tipos nativos
118             <acronym>PHP</acronym>
119             s, objetos
120             <classname>Zend_XmlRpc_Value</classname>
121             , o una combinación
122             de estos.
123         </para>
125         <para>
126             El método
127             <methodname>call()</methodname>
128             convertirá
129             automáticamente la respuesta
130             <acronym>XML-RPC</acronym>
131             y devolverá
132             su tipo nativo
133             <acronym>PHP</acronym>
134             equivalente. Un objeto
135             <classname>Zend_XmlRpc_Response</classname>
136             para el valor
137             devuelto también estará disponible para llamar el método
138             <methodname>getLastResponse()</methodname>
139             después de la
140             llamada.
141         </para>
142     </sect2>
144     <sect2 id="zend.xmlrpc.value.parameters">
145         <title>Tipos y Conversiones</title>
146         <para>
147             Algunas llamadas a métodos remoto requieren parámetros. Éstos son
148             dados al método
149             <methodname>call()</methodname>
150             de
151             <classname>Zend_XmlRpc_Client</classname>
152             como un array en el
153             segundo parámetro. Cada parámetro puede ser dado como un tipo nativo
154             <acronym>PHP</acronym>
155             , que será convertido automáticamente, o
156             como un objeto que representa un tipo específico
157             de
158             <acronym>XML-RPC</acronym>
159             (uno de los objetos
160             <classname>Zend_XmlRpc_Value</classname>
161             ).
162         </para>
164         <sect3 id="zend.xmlrpc.value.parameters.php-native">
165             <title>Tipos Nativos PHP como Parámetro</title>
166             <para>
167                 Los parámetros pueden ser pasados a
168                 <methodname>call()</methodname>
169                 como variables
170                 <acronym>PHP</acronym>
171                 nativas, ya sea un
172                 <type>string</type>
173                 ,
174                 <type>integer</type>
175                 ,
176                 <type>float</type>
177                 ,
178                 <type>boolean</type>
179                 ,
180                 <type>array</type>
181                 , o un
182                 <type>object</type>
183                 . En este caso, cada tipo
184                 <acronym>PHP</acronym>
185                 nativo será autodetectado y convertido en uno de los tipos
186                 <acronym>XML-RPC</acronym>
187                 de acuerdo con esta tabla:
188             </para>
190             <table id="zend.xmlrpc.value.parameters.php-native.table-1">
191                 <title>Tipos de Conversión entre PHP y
192                     XML-RPC</title>
193                 <tgroup cols="2">
194                     <thead>
195                         <row>
196                             <entry>
197                                 Tipo Nativo
198                                 <acronym>PHP</acronym>
199                             </entry>
200                             <entry>
201                                 Tipo
202                                 <acronym>XML-RPC</acronym>
203                             </entry>
204                         </row>
205                     </thead>
206                     <tbody>
207                         <row>
208                             <entry>integer</entry>
209                             <entry>int</entry>
210                         </row>
211                         <row>
212                             <entry>Zend_Crypt_Math_BigInteger</entry>
213                             <entry>i8</entry>
214                         </row>
216                             <row>
217                                 <entry>double</entry>
218                                 <entry>double</entry>
219                             </row>
220                             <row>
221                                 <entry>boolean</entry>
222                                 <entry>boolean</entry>
223                             </row>
224                             <row>
225                                 <entry>string</entry>
226                                 <entry>string</entry>
227                             </row>
228                             <row>
229                                 <entry>null</entry>
230                                 <entry>nil</entry>
231                             </row>
232                             <row>
233                                 <row>
234                                     <entry>array</entry>
235                                     <entry>array</entry>
236                                 </row>
237                                 <row>
238                                     <entry>array asociativo</entry>
239                                     <entry>struct</entry>
240                                 </row>
241                                 <row>
242                                     <entry>object</entry>
243                                     <entry>array</entry>
244                                 </row>
245                                 <row>
246                                     <entry>Zend_Date</entry>
247                                     <entry>dateTime.iso8601</entry>
248                                 </row>
249                                 <row>
250                                     <entry>DateTime</entry>
251                                     <entry>dateTime.iso8601</entry>
252                                 </row>
253                               </row>
254                     </tbody>
255                 </tgroup>
256             </table>
258             <note>
259                 <title>¿A qué tipo se convierten los arrays Vacios?</title>
261                 <para>
262                     Passing an empty array to an
263                     <acronym>XML-RPC</acronym>
264                     method is problematic,
265                     as it could represent either an array or a struct.
266                     <classname>Zend_XmlRpc_Client</classname>
267                     detects such conditions and
268                     makes a request to the server's
269                     <command>system.methodSignature</command>
270                     method to determine the
271                     appropriate
272                     <acronym>XML-RPC</acronym>
273                     type to cast to.
274                 </para>
276                 <para>
277                     However, this in itself can lead to issues. First off,
278                     servers that do not
279                     support
280                     <command>system.methodSignature</command>
281                     will log failed
282                     requests, and
283                     <classname>Zend_XmlRpc_Client</classname>
284                     will resort to
285                     casting the value to an
286                     <acronym>XML-RPC</acronym>
287                     array type. Additionally,
288                     this means that any call with array arguments will
289                     result in
290                     an additional call to the remote server.
291                 </para>
293                 <para>
294                     To disable the lookup entirely, you can call the
295                     <methodname>setSkipSystemLookup()</methodname>
296                     method prior to making
297                     your
298                     <acronym>XML-RPC</acronym>
299                     call:
300                 </para>
302                 <programlisting language="php"><![CDATA[
303 $client->setSkipSystemLookup(true);
304 $result = $client->call('foo.bar', array(array()));
305 ]]></programlisting>
306             </note>
307         </sect3>
309         <sect3 id="zend.xmlrpc.value.parameters.xmlrpc-value">
310             <title>Zend_XmlRpc_Value Objects as Parameters</title>
311             <para>
312                 Parameters may also be created as
313                 <classname>Zend_XmlRpc_Value</classname>
314                 instances to specify an exact
315                 <acronym>XML-RPC</acronym>
316                 type. The primary reasons
317                 for doing this are:
319                 <itemizedlist>
320                     <listitem>
321                         <para>
322                             When you want to make sure the correct parameter
323                             type is passed to the
324                             procedure (i.e. the
325                             procedure requires an integer and you may get it
326                             from
327                             a database as a string)
328                         </para>
329                     </listitem>
330                     <listitem>
331                         <para>
332                             When the procedure requires
333                             <property>base64</property>
334                             or
335                             <property>dateTime.iso8601</property>
336                             type (which doesn't exists as a
337                             <acronym>PHP</acronym>
338                             native type)
339                         </para>
340                     </listitem>
341                     <listitem>
342                         <para>
343                             When auto-conversion may fail (i.e. you want to
344                             pass an empty
345                             <acronym>XML-RPC</acronym>
346                             struct as a parameter. Empty
347                             structs are represented as empty arrays in
348                             <acronym>PHP</acronym>
349                             but, if you give an empty array as a parameter it
350                             will be auto-converted
351                             to an
352                             <acronym>XML-RPC</acronym>
353                             array since
354                             it's not an associative array)
355                         </para>
356                     </listitem>
357                 </itemizedlist>
358             </para>
360             <para>
361                 There are two ways to create a
362                 <classname>Zend_XmlRpc_Value</classname>
363                 object: instantiate one of the
364                 <classname>Zend_XmlRpc_Value</classname>
365                 subclasses directly, or use the static factory method
366                 <methodname>Zend_XmlRpc_Value::getXmlRpcValue()</methodname>
367                 .
368             </para>
370             <table id="zend.xmlrpc.value.parameters.xmlrpc-value.table-1">
371                 <title>Zend_XmlRpc_Value Objects for XML-RPC Types</title>
372                 <tgroup cols="3">
373                     <thead>
374                         <row>
375                             <entry>
376                                 <acronym>XML-RPC</acronym>
377                                 Type
378                             </entry>
379                             <entry>
380                                 <classname>Zend_XmlRpc_Value</classname>
381                                 Constant
382                             </entry>
383                             <entry>
384                                 <classname>Zend_XmlRpc_Value</classname>
385                                 Object
386                             </entry>
387                         </row>
388                     </thead>
389                     <tbody>
390                         <row>
391                             <entry>int</entry>
392                             <entry>
393                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_INTEGER</constant>
394                             </entry>
395                             <entry>
396                                 <classname>Zend_XmlRpc_Value_Integer</classname>
397                             </entry>
398                         </row>
399                         <row>
400                             <entry>i8</entry>
401                             <entry>
402                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_I8</constant>
403                             </entry>
404                             <entry>
405                                 <classname>Zend_XmlRpc_Value_BigInteger</classname>
406                             </entry>
407                         </row>
408                         <row>
409                             <entry>ex:i8</entry>
410                             <entry>
411                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_APACHEI8</constant>
412                             </entry>
413                             <entry>
414                                 <classname>Zend_XmlRpc_Value_BigInteger</classname>
415                             </entry>
416                         </row>
417                         <row>
418                             <entry>double</entry>
419                             <entry>
420                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_DOUBLE</constant>
421                             </entry>
422                             <entry>
423                                 <classname>Zend_XmlRpc_Value_Double</classname>
424                             </entry>
425                         </row>
426                         <row>
427                             <entry>boolean</entry>
428                             <entry>
429                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_BOOLEAN</constant>
430                             </entry>
431                             <entry>
432                                 <classname>Zend_XmlRpc_Value_Boolean</classname>
433                             </entry>
434                         </row>
435                         <row>
436                             <entry>string</entry>
437                             <entry>
438                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_STRING</constant>
439                             </entry>
440                             <entry>
441                                 <classname>Zend_XmlRpc_Value_String</classname>
442                             </entry>
443                         </row>
444                         <row>
445                             <entry>nil</entry>
446                             <entry>
447                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_NIL</constant>
448                             </entry>
449                             <entry>
450                                 <classname>Zend_XmlRpc_Value_Nil</classname>
451                             </entry>
452                         </row>
453                         <row>
454                             <entry>ex:nil</entry>
455                             <entry>
456                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_APACHENIL</constant>
457                             </entry>
458                             <entry>
459                                 <classname>Zend_XmlRpc_Value_Nil</classname>
460                             </entry>
461                         </row>
462                         <row>
463                             <entry>base64</entry>
464                             <entry>
465                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_BASE64</constant>
466                             </entry>
467                             <entry>
468                                 <classname>Zend_XmlRpc_Value_Base64</classname>
469                             </entry>
470                         </row>
471                         <row>
472                             <entry>dateTime.iso8601</entry>
473                             <entry>
474                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_DATETIME</constant>
475                             </entry>
476                             <entry>
477                                 <classname>Zend_XmlRpc_Value_DateTime</classname>
478                             </entry>
479                         </row>
480                         <row>
481                             <entry>array</entry>
482                             <entry>
483                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_ARRAY</constant>
484                             </entry>
485                             <entry>
486                                 <classname>Zend_XmlRpc_Value_Array</classname>
487                             </entry>
488                         </row>
489                         <row>
490                             <entry>struct</entry>
491                             <entry>
492                                 <constant>Zend_XmlRpc_Value::XMLRPC_TYPE_STRUCT</constant>
493                             </entry>
494                             <entry>
495                                 <classname>Zend_XmlRpc_Value_Struct</classname>
496                             </entry>
497                         </row>
498                     </tbody>
499                 </tgroup>
500             </table>
502             <para>
503                 <note>
504                     <title>Automatic Conversion</title>
505                     <para>
506                         When building a new
507                         <classname>Zend_XmlRpc_Value</classname>
508                         object, its value is set by a
509                         <acronym>PHP</acronym>
510                         type. The
511                         <acronym>PHP</acronym>
512                         type will be converted to the specified type using
513                         <acronym>PHP</acronym>
514                         casting. For example, if a string is given as a
515                         value to the
516                         <classname>Zend_XmlRpc_Value_Integer</classname>
517                         object, it will be converted using
518                         <command>(int)$value</command>
519                         .
520                     </para>
521                 </note>
522             </para>
523         </sect3>
524     </sect2>
526     <sect2 id="zend.xmlrpc.client.requests-and-responses">
527         <title>Server Proxy Object</title>
528         <para>
529             Another way to call remote methods with the
530             <acronym>XML-RPC</acronym>
531             client is to
532             use the server proxy. This is a
533             <acronym>PHP</acronym>
534             object that proxies a remote
535             <acronym>XML-RPC</acronym>
536             namespace, making it work as close to a native
537             <acronym>PHP</acronym>
538             object as possible.
539         </para>
541         <para>
542             To instantiate a server proxy, call the
543             <methodname>getProxy()</methodname>
544             instance method of
545             <classname>Zend_XmlRpc_Client</classname>
546             . This will
547             return an instance of
548             <classname>Zend_XmlRpc_Client_ServerProxy</classname>
549             .
550             Any method call on the server proxy object will be forwarded to
551             the remote, and
552             parameters may be passed like any other
553             <acronym>PHP</acronym>
554             method.
555         </para>
557         <example id="zend.xmlrpc.client.requests-and-responses.example-1">
558             <title>Proxy the Default Namespace</title>
559             <programlisting language="php"><![CDATA[
560 $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
562 $service = $client->getProxy();           // Proxy the default namespace
564 $hello = $service->test->sayHello(1, 2);  // test.Hello(1, 2) returns "hello"
565 ]]></programlisting>
566         </example>
568         <para>
569             The
570             <methodname>getProxy()</methodname>
571             method receives an optional argument
572             specifying which namespace of the remote server to
573             proxy. If it
574             does not receive a namespace, the default namespace will be
575             proxied. In the
576             next example, the 'test' namespace
577             will be proxied:
578         </para>
580         <example id="zend.xmlrpc.client.requests-and-responses.example-2">
581             <title>Proxy Any Namespace</title>
582             <programlisting language="php"><![CDATA[
583 $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
585 $test  = $client->getProxy('test');     // Proxy the "test" namespace
587 $hello = $test->sayHello(1, 2);         // test.Hello(1,2) returns "hello"
588 ]]></programlisting>
589         </example>
591         <para>
592             If the remote server supports nested namespaces of any depth,
593             these can also be used
594             through the server proxy. For example, if
595             the server in the example above had a method
596             <command>test.foo.bar()</command>
597             , it could be called as
598             <command>$test->foo->bar()</command>
599             .
600         </para>
601     </sect2>
603     <sect2 id="zend.xmlrpc.client.error-handling">
604         <title>Error Handling</title>
605         <para>
606             Two kinds of errors can occur during an
607             <acronym>XML-RPC</acronym>
608             method call:
609             <acronym>HTTP</acronym>
610             errors and
611             <acronym>XML-RPC</acronym>
612             faults. The
613             <classname>Zend_XmlRpc_Client</classname>
614             recognizes each and provides the ability
615             to detect and trap them independently.
616         </para>
618         <sect3 id="zend.xmlrpc.client.error-handling.http">
619             <title>HTTP Errors</title>
621             <para>
622                 If any
623                 <acronym>HTTP</acronym>
624                 error occurs, such as the remote
625                 <acronym>HTTP</acronym>
626                 server returns a
627                 <emphasis>404 Not Found</emphasis>
628                 , a
629                 <classname>Zend_XmlRpc_Client_HttpException</classname>
630                 will be thrown.
631             </para>
633             <example id="zend.xmlrpc.client.error-handling.http.example-1">
634                 <title>Handling HTTP Errors</title>
636                 <programlisting language="php"><![CDATA[
637 $client = new Zend_XmlRpc_Client('http://foo/404');
639 try {
641     $client->call('bar', array($arg1, $arg2));
643 } catch (Zend_XmlRpc_Client_HttpException $e) {
645     // $e->getCode() returns 404
646     // $e->getMessage() returns "Not Found"
649 ]]></programlisting>
650             </example>
652             <para>
653                 Regardless of how the
654                 <acronym>XML-RPC</acronym>
655                 client is used, the
656                 <classname>Zend_XmlRpc_Client_HttpException</classname>
657                 will be thrown
658                 whenever an
659                 <acronym>HTTP</acronym>
660                 error occurs.
661             </para>
662         </sect3>
664         <sect3 id="zend.xmlrpc.client.error-handling.faults">
665             <title>XML-RPC Faults</title>
667             <para>
668                 An
669                 <acronym>XML-RPC</acronym>
670                 fault is analogous to a
671                 <acronym>PHP</acronym>
672                 exception. It is a special type returned from an
673                 <acronym>XML-RPC</acronym>
674                 method
675                 call that has both an error code and an error message.
676                 <acronym>XML-RPC</acronym>
677                 faults are handled differently depending on the context of how the
678                 <classname>Zend_XmlRpc_Client</classname>
679                 is used.
680             </para>
682             <para>
683                 When the
684                 <methodname>call()</methodname>
685                 method or the server
686                 proxy object is used, an
687                 <acronym>XML-RPC</acronym>
688                 fault will result in a
689                 <classname>Zend_XmlRpc_Client_FaultException</classname>
690                 being thrown.
691                 The code and message of the exception will map directly to
692                 their
693                 respective values in the original
694                 <acronym>XML-RPC</acronym>
695                 fault
696                 response.
697             </para>
699             <example id="zend.xmlrpc.client.error-handling.faults.example-1">
700                 <title>Handling XML-RPC Faults</title>
702                 <programlisting language="php"><![CDATA[
703 $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
705 try {
707     $client->call('badMethod');
709 } catch (Zend_XmlRpc_Client_FaultException $e) {
711     // $e->getCode() returns 1
712     // $e->getMessage() returns "Unknown method"
715 ]]></programlisting>
716             </example>
718             <para>
719                 Cuando el método
720                 <methodname>call()</methodname>
721                 es usado
722                 para realizar la petición,
723                 <classname>Zend_XmlRpc_Client_FaultException</classname>
724                 será lanzado como error. Un objeto
725                 <classname>Zend_XmlRpc_Response</classname>
726                 conteniendo el
727                 error estará disponible llamando a
728                 <methodname>getLastResponse()</methodname>
729                 .
730             </para>
732             <para>
733                 Cuando el método
734                 <methodname>doRequest()</methodname>
735                 sea
736                 usado para realizar una petición, no lanzará una excepción. En
737                 vez de eso,
738                 devolverá un objeto
739                 <classname>Zend_XmlRpc_Response</classname>
740                 que contendrá
741                 el error. Esto puede comprobarse con
742                 <methodname>isFault()</methodname>
743                 método instancia de
744                 <classname>Zend_XmlRpc_Response</classname>
745                 .
746             </para>
747         </sect3>
749     </sect2>
751     <sect2 id="zend.xmlrpc.client.introspection">
752         <title>Server Introspection</title>
753         <para>
754             Some
755             <acronym>XML-RPC</acronym>
756             servers support the de facto introspection methods
757             under the
758             <acronym>XML-RPC</acronym>
759             <emphasis>system.</emphasis>
760             namespace.
761             <classname>Zend_XmlRpc_Client</classname>
762             provides special support for servers with
763             these capabilities.
764         </para>
766         <para>
767             A
768             <classname>Zend_XmlRpc_Client_ServerIntrospection</classname>
769             instance may be
770             retrieved by calling the
771             <methodname>getIntrospector()</methodname>
772             method of
773             <classname>Zend_XmlRpcClient</classname>
774             . It can then be used to perform introspection
775             operations on the server.
776         </para>
777     </sect2>
779     <sect2 id="zend.xmlrpc.client.request-to-response">
780         <title>From Request to Response</title>
781         <para>
782             Under the hood, the
783             <methodname>call()</methodname>
784             instance method of
785             <classname>Zend_XmlRpc_Client</classname>
786             builds a request object
787             (
788             <classname>Zend_XmlRpc_Request</classname>
789             ) and sends it to another method,
790             <methodname>doRequest()</methodname>
791             , that returns a response object
792             (
793             <classname>Zend_XmlRpc_Response</classname>
794             ).
795         </para>
797         <para>
798             The
799             <methodname>doRequest()</methodname>
800             method is also available for use directly:
801         </para>
803         <example id="zend.xmlrpc.client.request-to-response.example-1">
804             <title>Processing Request to Response</title>
806             <programlisting language="php"><![CDATA[
807 $client = new Zend_XmlRpc_Client('http://framework.zend.com/xmlrpc');
809 $request = new Zend_XmlRpc_Request();
810 $request->setMethod('test.sayHello');
811 $request->setParams(array('foo', 'bar'));
813 $client->doRequest($request);
815 // $client->getLastRequest() returns instanceof Zend_XmlRpc_Request
816 // $client->getLastResponse() returns instanceof Zend_XmlRpc_Response
817 ]]></programlisting>
818         </example>
820         <para>
821             Whenever an
822             <acronym>XML-RPC</acronym>
823             method call is made by the client through any
824             means, either the
825             <methodname>call()</methodname>
826             method,
827             <methodname>doRequest()</methodname>
828             method, or server proxy, the last request
829             object and its resultant response object will
830             always be available
831             through the methods
832             <methodname>getLastRequest()</methodname>
833             and
834             <methodname>getLastResponse()</methodname>
835             respectively.
836         </para>
837     </sect2>
839     <sect2 id="zend.xmlrpc.client.http-client">
840         <title>HTTP Client and Testing</title>
842         <para>
843             In all of the prior examples, an
844             <acronym>HTTP</acronym>
845             client was never specified.
846             When this is the case, a new instance of
847             <classname>Zend_Http_Client</classname>
848             will be created with its default
849             options and used by
850             <classname>Zend_XmlRpc_Client</classname>
851             automatically.
852         </para>
854         <para>
855             The
856             <acronym>HTTP</acronym>
857             client can be retrieved at any time with the
858             <methodname>getHttpClient()</methodname>
859             method. For most cases, the default
860             <acronym>HTTP</acronym>
861             client will be sufficient. However, the
862             <methodname>setHttpClient()</methodname>
863             method allows for a different
864             <acronym>HTTP</acronym>
865             client instance to be injected.
866         </para>
868         <para>
869             The
870             <methodname>setHttpClient()</methodname>
871             is particularly useful for unit testing.
872             When combined with the
873             <classname>Zend_Http_Client_Adapter_Test</classname>
874             , remote
875             services can be mocked out for testing. See the unit tests for
876             <classname>Zend_XmlRpc_Client</classname>
877             for examples of how to do this.
878         </para>
879     </sect2>
881 </sect1>
882     <!--
883 vim:se ts=4 sw=4 et: