Zend_XmlRpc_Client.xml 32 KB

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