Zend_Service_StrikeIron-AdvancedUses.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.strikeiron.advanced-uses">
  4. <title>Zend_Service_StrikeIron: Advanced Uses</title>
  5. <para>
  6. This section describes the more advanced uses of
  7. <classname>Zend_Service_StrikeIron</classname>.
  8. </para>
  9. <sect2 id="zend.service.strikeiron.advanced-uses.services-by-wsdl">
  10. <title>Using Services by WSDL</title>
  11. <para>
  12. Some StrikeIron services may have a <acronym>PHP</acronym> wrapper class available,
  13. such as those described in
  14. <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>.
  15. However, StrikeIron offers hundreds of services and many of these
  16. may be usable even without creating a special wrapper class.
  17. </para>
  18. <para>
  19. To try a StrikeIron service that does not have a wrapper class available,
  20. give the <code>wsdl</code> option to <methodname>getService()</methodname>
  21. instead of the <code>class</code> option:
  22. <programlisting language="php"><![CDATA[
  23. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  24. 'password' => 'your-password'));
  25. // Get a generic client to the Reverse Phone Lookup service
  26. $phone = $strikeIron->getService(
  27. array('wsdl' => 'http://ws.strikeiron.com/ReversePhoneLookup?WSDL')
  28. );
  29. $result = $phone->lookup(array('Number' => '(408) 253-8800'));
  30. echo $result->listingName;
  31. // Zend Technologies USA Inc
  32. ]]></programlisting>
  33. </para>
  34. <para>
  35. Using StrikeIron services from the WSDL will require at least some understanding
  36. of the WSDL files. StrikeIron has many resources on its site to help with this. Also,
  37. <ulink url="http://janschneider.de">Jan Schneider</ulink> from the <ulink
  38. url="http://horde.org">Horde project</ulink> has written a <ulink
  39. url="http://janschneider.de/news/25/268">small <acronym>PHP</acronym>
  40. routine</ulink> that will format a WSDL file into more readable HTML.
  41. </para>
  42. <para>
  43. Please note that only the services described in the <link
  44. linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
  45. section are officially supported.
  46. </para>
  47. </sect2>
  48. <sect2 id="zend.service.strikeiron.viewing-soap-transactions">
  49. <title>Viewing SOAP Transactions</title>
  50. <para>
  51. All communication with StrikeIron is done using the <acronym>SOAP</acronym> extension.
  52. It is sometimes useful to view the <acronym>XML</acronym> exchanged with StrikeIron for
  53. debug purposes.
  54. </para>
  55. <para>
  56. Every StrikeIron client (subclass of
  57. <classname>Zend_Service_StrikeIron_Base</classname>) contains a
  58. <methodname>getSoapClient()</methodname> method to return the underlying instance of
  59. <code>SOAPClient</code> used to communicate with StrikeIron.
  60. </para>
  61. <para>
  62. <acronym>PHP</acronym>' <ulink
  63. url="http://www.php.net/manual/en/function.soap-soapclient-construct.php">SOAPClient</ulink>
  64. has a <code>trace</code> option that causes it to remember the <acronym>XML</acronym>
  65. exchanged during the last transaction. <classname>Zend_Service_StrikeIron</classname>
  66. does not enable the <code>trace</code> option by default but this can easily by changed
  67. by specifying the options that will be passed to the <code>SOAPClient</code>
  68. constructor.
  69. </para>
  70. <para>
  71. To view a SOAP transaction, call the <methodname>getSoapClient()</methodname> method
  72. to get the <code>SOAPClient</code> instance and then call the appropriate methods like
  73. <ulink
  74. url="http://www.php.net/manual/en/function.soap-soapclient-getlastrequest.php"><methodname>__getLastRequest()</methodname></ulink>
  75. and <ulink
  76. url="http://www.php.net/manual/en/function.soap-soapclient-getlastresponse.php"><methodname>__getLastRequest()</methodname></ulink>:
  77. <programlisting language="php"><![CDATA[
  78. $strikeIron =
  79. new Zend_Service_StrikeIron(array('username' => 'your-username',
  80. 'password' => 'your-password',
  81. 'options' => array('trace' => true)));
  82. // Get a client for the Sales & Use Tax Basic service
  83. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  84. // Perform a method call
  85. $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  86. // Get SOAPClient instance and view XML
  87. $soapClient = $taxBasic->getSoapClient();
  88. echo $soapClient->__getLastRequest();
  89. echo $soapClient->__getLastResponse();
  90. ]]></programlisting>
  91. </para>
  92. </sect2>
  93. </sect1>