| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!-- Reviewed: no -->
- <sect1 id="zend.soap.autodiscovery">
- <title>AutoDiscovery</title>
- <sect2 id="zend.soap.autodiscovery.introduction">
- <title>AutoDiscovery Introduction</title>
- <para>
- SOAP functionality implemented within Zend Framework is intended to make all steps
- required for SOAP communications more simple.
- </para>
- <para>
- SOAP is language independent protocol. So it may be used not only for PHP-to-PHP communications.
- </para>
- <para>
- There are three configurations for SOAP applications where Zend Framework may be utilized:
- <orderedlist>
- <listitem>
- <simpara>SOAP server PHP application <---> SOAP client PHP application</simpara>
- </listitem>
- <listitem>
- <simpara>SOAP server non-PHP application <---> SOAP client PHP application</simpara>
- </listitem>
- <listitem>
- <simpara>SOAP server PHP application <---> SOAP client non-PHP application</simpara>
- </listitem>
- </orderedlist>
- </para>
- <para>
- We always have to know, which functionality is provided by SOAP server to operate with it.
- <ulink url="http://www.w3.org/TR/wsdl">WSDL</ulink> is used to describe network service API
- in details.
- </para>
- <para>
- WSDL language is complex enough (see <ulink url="http://www.w3.org/TR/wsdl">http://www.w3.org/TR/wsdl</ulink>
- for the details). So it's difficult to prepare correct WSDL description.
- </para>
- <para>
- Another problem is synchronizing changes in network service API with already existing WSDL.
- </para>
- <para>
- Both these problem may be solved by WSDL autogeneration. A prerequisite for this is a SOAP server autodiscovery.
- It constructs object similar to object used in SOAP server application, extracts necessary information and generates
- correct WSDL using this information.
- </para>
- <para>
- There are two ways for using Zend Framework for SOAP server application:
- <itemizedlist>
- <listitem>
- <para>Use separated class.</para>
- </listitem>
- <listitem>
- <para>Use set of functions</para>
- </listitem>
- </itemizedlist>
- </para>
- <para>
- Both methods are supported by Zend Framework Autodiscovery functionality.
- </para>
- <para>
- The<classname>Zend_Soap_AutoDiscover</classname> class also supports datatypes mapping from PHP to <ulink url="http://www.w3.org/TR/xmlschema-2/">XSD types</ulink>.
- </para>
- <para>
- Here is an example of common usage of the autodiscovery functionality. The <code>handle()</code>
- function generates the WSDL file and posts it to the browser.
- <programlisting language="php"><![CDATA[
- class My_SoapServer_Class {
- ...
- }
- $autodiscover = new Zend_Soap_AutoDiscover();
- $autodiscover->setClass('My_SoapServer_Class');
- $autodiscover->handle();
- ]]></programlisting>
- </para>
- <para>
- If you need access to the generated WSDL file either to save it to a file or
- as an XML string you can use the <code>dump($filename)</code> or <code>toXml()</code>
- functions the AutoDiscover class provides.
- </para>
- <note id="zend.soap.autodiscovery.introduction.noserver">
- <title>Zend_Soap_Autodiscover is not a Soap Server</title>
- <para>
- It is very important to note, that the class <classname>Zend_Soap_AutoDiscover</classname> does not act
- as a SOAP Server on its own. It only generates the WSDL and serves it to anyone accessing
- the url it is listening on.
- </para>
- <para>
- As the SOAP Endpoint Uri is uses the default
- <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code>,
- but this can be changed with the <code>setUri()</code> function or the Constructor
- parameter of <classname>Zend_Soap_AutoDiscover</classname> class. The endpoint has to provide
- a <classname>Zend_Soap_Server</classname> that listens to requests.
- </para>
- <para>
- <programlisting language="php"><![CDATA[
- if(isset($_GET['wsdl'])) {
- $autodiscover = new Zend_Soap_AutoDiscover();
- $autodiscover->setClass('HelloWorldService');
- $autodiscover->handle();
- } else {
- // pointing to the current file here
- $soap = new Zend_Soap_Server("http://example.com/soap.php?wsdl");
- $soap->setClass('HelloWorldService');
- $soap->handle();
- }
- ]]></programlisting>
- </para>
- </note>
- </sect2>
- <sect2 id="zend.soap.autodiscovery.class">
- <title>Class autodiscovering</title>
- <para>
- If class is used to provide SOAP server functionality, then the same class should be provided to
- <classname>Zend_Soap_AutoDiscover</classname> for WSDL generation:
- <programlisting language="php"><![CDATA[
- $autodiscover = new Zend_Soap_AutoDiscover();
- $autodiscover->setClass('My_SoapServer_Class');
- $autodiscover->handle();
- ]]></programlisting>
- </para>
- <para>
- The following rules are used while WSDL generation:
- <itemizedlist>
- <listitem>
- <para>Generated WSDL describes an RPC style Web Service.</para>
- </listitem>
- <listitem>
- <para>Class name is used as a name of the Web Service being described.</para>
- </listitem>
- <listitem>
- <para>
- <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code> is used
- as an URI where the WSDL is available by default but can be overwritten via <code>setUri()</code> method.
- </para>
- <para>
- It's also used as a target namespace for all service related names (including
- described complex types).
- </para>
- </listitem>
- <listitem>
- <para>
- Class methods are joined into one <ulink url="http://www.w3.org/TR/wsdl#_porttypes">Port Type</ulink>.
- </para>
- <para>
- <code>$className . 'Port'</code> is used as Port Type name.
- </para>
- </listitem>
- <listitem>
- <para>Each class method is registered as a corresponding port operation.</para>
- </listitem>
- <listitem>
- <para>Each method prototype generates corresponding Request/Response messages.</para>
- <para>Method may have several prototypes if some method parameters are optional.</para>
- </listitem>
- </itemizedlist>
- </para>
- <note>
- <title>Important!</title>
- <para>
- WSDL autodiscovery utilizes the PHP docblocks provided by the developer to determine the parameter and return types.
- In fact, for scalar types, this is the only way to determine the parameter types, and for return types, this is the
- only way to determine them.
- </para>
- <para>
- That means, providing correct and fully detailed docblocks is not only best practice, but is required for discovered class.
- </para>
- </note>
- </sect2>
- <sect2 id="zend.soap.autodiscovery.functions">
- <title>Functions autodiscovering</title>
- <para>
- If set of functions are used to provide SOAP server functionality, then the same set should be provided to
- <classname>Zend_Soap_AutoDiscovery</classname> for WSDL generation:
- <programlisting language="php"><![CDATA[
- $autodiscover = new Zend_Soap_AutoDiscover();
- $autodiscover->addFunction('function1');
- $autodiscover->addFunction('function2');
- $autodiscover->addFunction('function3');
- ...
- $autodiscover->handle();
- ]]></programlisting>
- </para>
- <para>
- The following rules are used while WSDL generation:
- <itemizedlist>
- <listitem>
- <para>Generated WSDL describes an RPC style Web Service.</para>
- </listitem>
- <listitem>
- <para>Current script name is used as a name of the Web Service being described.</para>
- </listitem>
- <listitem>
- <para>
- <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code> is used
- as an URI where the WSDL is available.
- </para>
- <para>
- It's also used as a target namespace for all service related names (including
- described complex types).
- </para>
- </listitem>
- <listitem>
- <para>
- Functions are joined into one <ulink url="http://www.w3.org/TR/wsdl#_porttypes">Port Type</ulink>.
- </para>
- <para>
- <code>$functionName . 'Port'</code> is used as Port Type name.
- </para>
- </listitem>
- <listitem>
- <para>Each function is registered as a corresponding port operation.</para>
- </listitem>
- <listitem>
- <para>Each function prototype generates corresponding Request/Response messages.</para>
- <para>Function may have several prototypes if some method parameters are optional.</para>
- </listitem>
- </itemizedlist>
- </para>
- <note>
- <title>Important!</title>
- <para>
- WSDL autodiscovery utilizes the PHP docblocks provided by the developer to determine the parameter and return types.
- In fact, for scalar types, this is the only way to determine the parameter types, and for return types, this is the
- only way to determine them.
- </para>
- <para>
- That means, providing correct and fully detailed docblocks is not only best practice, but is required for discovered class.
- </para>
- </note>
- </sect2>
- <sect2 id="zend.soap.autodiscovery.datatypes">
- <title>Autodiscovering Datatypes</title>
- <para>
- Input/output datatypes are converted into network service types using the following mapping:
- <itemizedlist>
- <listitem>
- <para>PHP strings <-> <code>xsd:string</code>.</para>
- </listitem>
- <listitem>
- <para>PHP integers <-> <code>xsd:int</code>.</para>
- </listitem>
- <listitem>
- <para>PHP floats and doubles <-> <code>xsd:float</code>.</para>
- </listitem>
- <listitem>
- <para>PHP booleans <-> <code>xsd:boolean</code>.</para>
- </listitem>
- <listitem>
- <para>PHP arrays <-> <code>soap-enc:Array</code>.</para>
- </listitem>
- <listitem>
- <para>PHP object <-> <code>xsd:struct</code>.</para>
- </listitem>
- <listitem>
- <para>
- PHP class <-> based on complex type strategy (See: <xref linkend="zend.soap.wsdl.types.add_complex" />)
- <footnote>
- <para>
- <classname>Zend_Soap_AutoDiscover</classname> will be created with the <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>
- class as detection algorithm for complex types. The first parameter of the AutoDiscover constructor takes
- any complex type strategy implementing <classname>Zend_Soap_Wsdl_Strategy_Interface</classname> or a string with the name
- of the class. For backwards compatibility with <code>$extractComplexType</code> boolean variables are parsed
- exactly like in <classname>Zend_Soap_Wsdl</classname>. See the <link linkend="zend.soap.wsdl.types.add_complex"><classname>Zend_Soap_Wsdl</classname> manual
- on adding complex</link> types for more information.
- </para>
- </footnote>.
- </para>
- </listitem>
- <listitem>
- <para>type[] or object[] (ie. int[]) <-> based on complex type strategy</para>
- </listitem>
- <listitem>
- <para>PHP void <-> empty type.</para>
- </listitem>
- <listitem>
- <para>If type is not matched to any of these types by some reason, then <code>xsd:anyType</code> is used.</para>
- </listitem>
- </itemizedlist>
- Where <code>xsd:</code> is "http://www.w3.org/2001/XMLSchema" namespace,
- <code>soap-enc:</code> is a "http://schemas.xmlsoap.org/soap/encoding/" namespace,
- <code>tns:</code> is a "target namespace" for a service.
- </para>
- </sect2>
- <sect2 id="zend.soap.autodiscovery.wsdlstyles">
- <title>WSDL Binding Styles</title>
- <para>
- WSDL offers different transport mechanisms and styles. This affects the
- <code>soap:binding</code> and <code>soap:body</code> tags within the Binding
- section of WSDL. Different clients have different requirements as to what options
- really work. Therefore you can set the styles before you call any <code>setClass</code>
- or <code>addFunction</code> method on the AutoDiscover class.
- </para>
- <para>
- <programlisting language="php"><![CDATA[
- $autodiscover = new Zend_Soap_AutoDiscover();
- // Default is 'use' => 'encoded' and
- // 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
- $autodiscover->setOperationBodyStyle(
- array('use' => 'literal',
- 'namespace' => 'http://framework.zend.com')
- );
- // Default is 'style' => 'rpc' and
- // 'transport' => 'http://schemas.xmlsoap.org/soap/http'
- $autodiscover->setBindingStyle(
- array('style' => 'document',
- 'transport' => 'http://framework.zend.com')
- );
- ...
- $autodiscover->addFunction('myfunc1');
- $autodiscover->handle();
- ]]></programlisting>
- </para>
- </sect2>
- </sect1>
|