File: Zend_Service_StrikeIron-AdvancedUses.xml

package info (click to toggle)
zendframework 1.12.9%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 133,584 kB
  • sloc: xml: 1,311,829; php: 570,173; sh: 170; makefile: 125; sql: 121
file content (114 lines) | stat: -rw-r--r-- 5,102 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.service.strikeiron.advanced-uses">
    <title>Zend_Service_StrikeIron: Advanced Uses</title>

    <para>
        This section describes the more advanced uses of
        <classname>Zend_Service_StrikeIron</classname>.
    </para>

    <sect2 id="zend.service.strikeiron.advanced-uses.services-by-wsdl">
        <title>Using Services by WSDL</title>

        <para>
            Some StrikeIron services may have a <acronym>PHP</acronym> wrapper class available,
            such as those described in
            <link linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>.
            However, StrikeIron offers hundreds of services and many of these
            may be usable even without creating a special wrapper class.
        </para>

        <para>
            To try a StrikeIron service that does not have a wrapper class available,
            give the <property>wsdl</property> option to <methodname>getService()</methodname>
            instead of the <property>class</property> option:
        </para>

        <programlisting language="php"><![CDATA[
$strikeIron = new Zend_Service_StrikeIron(array('username' => 'your-username',
                                                'password' => 'your-password'));

// Get a generic client to the Reverse Phone Lookup service
$phone = $strikeIron->getService(
    array('wsdl' => 'http://ws.strikeiron.com/ReversePhoneLookup?WSDL')
);

$result = $phone->lookup(array('Number' => '(408) 253-8800'));
echo $result->listingName;

// Zend Technologies USA Inc
]]></programlisting>

        <para>
            Using StrikeIron services from the WSDL will require at least some understanding
            of the WSDL files. StrikeIron has many resources on its site to help with this. Also,
            <ulink url="http://janschneider.de">Jan Schneider</ulink> from the <ulink
                url="http://horde.org">Horde project</ulink> has written a <ulink
                url="http://janschneider.de/news/25/268">small <acronym>PHP</acronym>
                routine</ulink> that will format a WSDL file into more readable
            <acronym>HTML</acronym>.
        </para>

        <para>
            Please note that only the services described in the <link
                linkend="zend.service.strikeiron.bundled-services">Bundled Services</link>
            section are officially supported.
        </para>
    </sect2>

    <sect2 id="zend.service.strikeiron.viewing-soap-transactions">
        <title>Viewing SOAP Transactions</title>

        <para>
            All communication with StrikeIron is done using the <acronym>SOAP</acronym> extension.
            It is sometimes useful to view the <acronym>XML</acronym> exchanged with StrikeIron for
            debug purposes.
        </para>

        <para>
            Every StrikeIron client (subclass of
            <classname>Zend_Service_StrikeIron_Base</classname>) contains a
            <methodname>getSoapClient()</methodname> method to return the underlying instance of
            <classname>SOAPClient</classname> used to communicate with StrikeIron.
        </para>

        <para>
            <acronym>PHP</acronym>' <ulink
                url="http://www.php.net/manual/en/function.soap-soapclient-construct.php">SOAPClient</ulink>
            has a <property>trace</property> option that causes it to remember the
            <acronym>XML</acronym> exchanged during the last transaction.
            <classname>Zend_Service_StrikeIron</classname> does not enable the
            <property>trace</property> option by default but this can easily by changed
            by specifying the options that will be passed to the <classname>SOAPClient</classname>
            constructor.
        </para>

        <para>
            To view a SOAP transaction, call the <methodname>getSoapClient()</methodname> method
            to get the <classname>SOAPClient</classname> instance and then call the appropriate
            methods like <ulink
                url="http://www.php.net/manual/en/function.soap-soapclient-getlastrequest.php"><methodname>__getLastRequest()</methodname></ulink>
            and <ulink
                url="http://www.php.net/manual/en/function.soap-soapclient-getlastresponse.php"><methodname>__getLastRequest()</methodname></ulink>:
        </para>

        <programlisting language="php"><![CDATA[
$strikeIron =
    new Zend_Service_StrikeIron(array('username' => 'your-username',
                                      'password' => 'your-password',
                                      'options'  => array('trace' => true)));

// Get a client for the Sales & Use Tax Basic service
$taxBasic = $strikeIron->getService(array('class' => 'SalesUseTaxBasic'));

// Perform a method call
$taxBasic->getTaxRateCanada(array('province' => 'ontario'));

// Get SOAPClient instance and view XML
$soapClient = $taxBasic->getSoapClient();
echo $soapClient->__getLastRequest();
echo $soapClient->__getLastResponse();
]]></programlisting>
    </sect2>
</sect1>