Zend_Service_StrikeIron-AdvancedUses.xml 4.5 KB

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