Zend_Service_StrikeIron-AdvancedUses.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <property>wsdl</property> option to <methodname>getService()</methodname>
  21. instead of the <property>class</property> option:
  22. </para>
  23. <programlisting language="php"><![CDATA[
  24. $strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
  25. 'password' => 'your-password'));
  26. // Get a generic client to the Reverse Phone Lookup service
  27. $phone = $strikeIron->getService(
  28. array('wsdl' => 'http://ws.strikeiron.com/ReversePhoneLookup?WSDL')
  29. );
  30. $result = $phone->lookup(array('Number' => '(408) 253-8800'));
  31. echo $result->listingName;
  32. // Zend Technologies USA Inc
  33. ]]></programlisting>
  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
  41. <acronym>HTML</acronym>.
  42. </para>
  43. <para>
  44. Please note that only the services described in the <link
  45. linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
  46. section are officially supported.
  47. </para>
  48. </sect2>
  49. <sect2 id="zend.service.strikeiron.viewing-soap-transactions">
  50. <title>Viewing SOAP Transactions</title>
  51. <para>
  52. All communication with StrikeIron is done using the <acronym>SOAP</acronym> extension.
  53. It is sometimes useful to view the <acronym>XML</acronym> exchanged with StrikeIron for
  54. debug purposes.
  55. </para>
  56. <para>
  57. Every StrikeIron client (subclass of
  58. <classname>Zend_Service_StrikeIron_Base</classname>) contains a
  59. <methodname>getSoapClient()</methodname> method to return the underlying instance of
  60. <classname>SOAPClient</classname> used to communicate with StrikeIron.
  61. </para>
  62. <para>
  63. <acronym>PHP</acronym>' <ulink
  64. url="http://www.php.net/manual/en/function.soap-soapclient-construct.php">SOAPClient</ulink>
  65. has a <property>trace</property> option that causes it to remember the
  66. <acronym>XML</acronym> exchanged during the last transaction.
  67. <classname>Zend_Service_StrikeIron</classname> does not enable the
  68. <property>trace</property> option by default but this can easily by changed
  69. by specifying the options that will be passed to the <classname>SOAPClient</classname>
  70. constructor.
  71. </para>
  72. <para>
  73. To view a SOAP transaction, call the <methodname>getSoapClient()</methodname> method
  74. to get the <classname>SOAPClient</classname> instance and then call the appropriate
  75. methods like <ulink
  76. url="http://www.php.net/manual/en/function.soap-soapclient-getlastrequest.php"><methodname>__getLastRequest()</methodname></ulink>
  77. and <ulink
  78. url="http://www.php.net/manual/en/function.soap-soapclient-getlastresponse.php"><methodname>__getLastRequest()</methodname></ulink>:
  79. </para>
  80. <programlisting language="php"><![CDATA[
  81. $strikeIron =
  82. new Zend_Service_StrikeIron(array('username' => 'your-username',
  83. 'password' => 'your-password',
  84. 'options' => array('trace' => true)));
  85. // Get a client for the Sales & Use Tax Basic service
  86. $taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));
  87. // Perform a method call
  88. $taxBasic->getTaxRateCanada(array('province' => 'ontario'));
  89. // Get SOAPClient instance and view XML
  90. $soapClient = $taxBasic->getSoapClient();
  91. echo $soapClient->__getLastRequest();
  92. echo $soapClient->__getLastResponse();
  93. ]]></programlisting>
  94. </sect2>
  95. </sect1>