1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.soap.autodiscovery">
4 <title>AutoDiscovery</title>
6 <sect2 id="zend.soap.autodiscovery.introduction">
7 <title>AutoDiscovery Introduction</title>
10 <acronym>SOAP</acronym> functionality implemented within Zend Framework is intended to
11 make all steps required for <acronym>SOAP</acronym> communications more simple.
15 <acronym>SOAP</acronym> is language independent protocol. So it may be used not only for
16 <acronym>PHP</acronym>-to-PHP communications.
20 There are three configurations for <acronym>SOAP</acronym> applications where Zend
21 Framework may be utilized:
26 SOAP server <acronym>PHP</acronym> application <--->
27 <acronym>SOAP</acronym> client <acronym>PHP</acronym> application
33 SOAP server non-PHP application <---> <acronym>SOAP</acronym>
34 client <acronym>PHP</acronym> application
40 SOAP server <acronym>PHP</acronym> application <--->
41 <acronym>SOAP</acronym> client non-PHP application
48 We always have to know, which functionality is provided by <acronym>SOAP</acronym>
49 server to operate with it. <ulink url="http://www.w3.org/TR/wsdl">WSDL</ulink> is used
50 to describe network service <acronym>API</acronym> in details.
54 WSDL language is complex enough (see <ulink
55 url="http://www.w3.org/TR/wsdl">http://www.w3.org/TR/wsdl</ulink>
56 for the details). So it's difficult to prepare correct WSDL description.
60 Another problem is synchronizing changes in network service <acronym>API</acronym> with
61 already existing WSDL.
65 Both these problem may be solved by WSDL autogeneration. A prerequisite for this is a
66 <acronym>SOAP</acronym> server autodiscovery. It constructs object similar to object
67 used in <acronym>SOAP</acronym> server application, extracts necessary information and
68 generates correct WSDL using this information.
72 There are two ways for using Zend Framework for <acronym>SOAP</acronym> server
77 <para>Use separated class.</para>
81 <para>Use set of functions</para>
87 Both methods are supported by Zend Framework Autodiscovery functionality.
91 The<classname>Zend_Soap_AutoDiscover</classname> class also supports datatypes mapping
92 from <acronym>PHP</acronym> to <ulink
93 url="http://www.w3.org/TR/xmlschema-2/">XSD types</ulink>.
97 Here is an example of common usage of the autodiscovery functionality. The
98 <methodname>handle()</methodname> function generates the WSDL file and posts it to the
101 <programlisting language="php"><![CDATA[
102 class My_SoapServer_Class {
106 $autodiscover = new Zend_Soap_AutoDiscover();
107 $autodiscover->setClass('My_SoapServer_Class');
108 $autodiscover->handle();
113 If you need access to the generated WSDL file either to save it to a file or as an
114 <acronym>XML</acronym> string you can use the <methodname>dump($filename)</methodname>
115 or <methodname>toXml()</methodname> functions the AutoDiscover class provides.
118 <note id="zend.soap.autodiscovery.introduction.noserver">
119 <title>Zend_Soap_Autodiscover is not a Soap Server</title>
122 It is very important to note, that the class
123 <classname>Zend_Soap_AutoDiscover</classname> does not act as a
124 <acronym>SOAP</acronym> Server on its own. It only generates the WSDL and serves it
125 to anyone accessing the url it is listening on.
129 As the <acronym>SOAP</acronym> Endpoint Uri is uses the default
130 <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code>, but this
131 can be changed with the <methodname>setUri()</methodname> function or the
132 Constructor parameter of <classname>Zend_Soap_AutoDiscover</classname> class. The
133 endpoint has to provide a <classname>Zend_Soap_Server</classname> that listens to
138 <programlisting language="php"><![CDATA[
139 if(isset($_GET['wsdl'])) {
140 $autodiscover = new Zend_Soap_AutoDiscover();
141 $autodiscover->setClass('HelloWorldService');
142 $autodiscover->handle();
144 // pointing to the current file here
145 $soap = new Zend_Soap_Server("http://example.com/soap.php?wsdl");
146 $soap->setClass('HelloWorldService');
154 <sect2 id="zend.soap.autodiscovery.class">
155 <title>Class autodiscovering</title>
158 If class is used to provide SOAP server functionality, then the same class should be
159 provided to <classname>Zend_Soap_AutoDiscover</classname> for WSDL generation:
161 <programlisting language="php"><![CDATA[
162 $autodiscover = new Zend_Soap_AutoDiscover();
163 $autodiscover->setClass('My_SoapServer_Class');
164 $autodiscover->handle();
169 The following rules are used while WSDL generation:
173 <para>Generated WSDL describes an RPC style Web Service.</para>
177 <para>Class name is used as a name of the Web Service being described.</para>
182 <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code> is
183 used as an <acronym>URI</acronym> where the WSDL is available by default but
184 can be overwritten via <methodname>setUri()</methodname> method.
188 It's also used as a target namespace for all service related names
189 (including described complex types).
195 Class methods are joined into one <ulink
196 url="http://www.w3.org/TR/wsdl#_porttypes">Port Type</ulink>.
200 <code>$className . 'Port'</code> is used as Port Type name.
205 <para>Each class method is registered as a corresponding port operation.</para>
210 Each method prototype generates corresponding Request/Response messages.
214 Method may have several prototypes if some method parameters are optional.
221 <title>Important!</title>
224 WSDL autodiscovery utilizes the <acronym>PHP</acronym> docblocks provided by the
225 developer to determine the parameter and return types. In fact, for scalar types,
226 this is the only way to determine the parameter types, and for return types, this is
227 the only way to determine them.
231 That means, providing correct and fully detailed docblocks is not only best
232 practice, but is required for discovered class.
237 <sect2 id="zend.soap.autodiscovery.functions">
238 <title>Functions autodiscovering</title>
241 If set of functions are used to provide SOAP server functionality, then the same set
242 should be provided to <classname>Zend_Soap_AutoDiscovery</classname> for WSDL
245 <programlisting language="php"><![CDATA[
246 $autodiscover = new Zend_Soap_AutoDiscover();
247 $autodiscover->addFunction('function1');
248 $autodiscover->addFunction('function2');
249 $autodiscover->addFunction('function3');
251 $autodiscover->handle();
256 The following rules are used while WSDL generation:
260 <para>Generated WSDL describes an RPC style Web Service.</para>
265 Current script name is used as a name of the Web Service being described.
271 <code>'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']</code> is
272 used as an <acronym>URI</acronym> where the WSDL is available.
276 It's also used as a target namespace for all service related names
277 (including described complex types).
283 Functions are joined into one <ulink
284 url="http://www.w3.org/TR/wsdl#_porttypes">Port Type</ulink>.
288 <code>$functionName . 'Port'</code> is used as Port Type name.
293 <para>Each function is registered as a corresponding port operation.</para>
298 Each function prototype generates corresponding Request/Response messages.
302 Function may have several prototypes if some method parameters are optional.
309 <title>Important!</title>
312 WSDL autodiscovery utilizes the <acronym>PHP</acronym> docblocks provided by the
313 developer to determine the parameter and return types. In fact, for scalar types,
314 this is the only way to determine the parameter types, and for return types, this is
315 the only way to determine them.
319 That means, providing correct and fully detailed docblocks is not only best
320 practice, but is required for discovered class.
325 <sect2 id="zend.soap.autodiscovery.datatypes">
326 <title>Autodiscovering Datatypes</title>
329 Input/output datatypes are converted into network service types using the following
334 <para>PHP strings <-> <code>xsd:string</code>.</para>
338 <para>PHP integers <-> <code>xsd:int</code>.</para>
342 <para>PHP floats and doubles <-> <code>xsd:float</code>.</para>
346 <para>PHP booleans <-> <code>xsd:boolean</code>.</para>
350 <para>PHP arrays <-> <code>soap-enc:Array</code>.</para>
354 <para>PHP object <-> <code>xsd:struct</code>.</para>
359 <acronym>PHP</acronym> class <-> based on complex type strategy (See:
360 <xref linkend="zend.soap.wsdl.types.add_complex" />)
364 <classname>Zend_Soap_AutoDiscover</classname> will be created with
366 <classname>Zend_Soap_Wsdl_Strategy_DefaultComplexType</classname>
367 class as detection algorithm for complex types. The first parameter
368 of the AutoDiscover constructor takes any complex type strategy
370 <classname>Zend_Soap_Wsdl_Strategy_Interface</classname> or a string
371 with the name of the class. For backwards compatibility with
372 <varname>$extractComplexType</varname> boolean variables are parsed
373 exactly like in <classname>Zend_Soap_Wsdl</classname>. See the
375 linkend="zend.soap.wsdl.types.add_complex"><classname>Zend_Soap_Wsdl</classname>
376 manual on adding complex</link> types for more information.
384 type[] or object[] (ie. int[]) <-> based on complex type strategy
389 <para>PHP void <-> empty type.</para>
394 If type is not matched to any of these types by some reason, then
395 <code>xsd:anyType</code> is used.
400 Where <code>xsd:</code> is "http://www.w3.org/2001/XMLSchema" namespace,
401 <code>soap-enc:</code> is a "http://schemas.xmlsoap.org/soap/encoding/" namespace,
402 <code>tns:</code> is a "target namespace" for a service.
406 <sect2 id="zend.soap.autodiscovery.wsdlstyles">
407 <title>WSDL Binding Styles</title>
410 WSDL offers different transport mechanisms and styles. This affects the
411 <code>soap:binding</code> and <code>soap:body</code> tags within the Binding
412 section of WSDL. Different clients have different requirements as to what options
413 really work. Therefore you can set the styles before you call any <code>setClass</code>
414 or <code>addFunction</code> method on the AutoDiscover class.
418 <programlisting language="php"><![CDATA[
419 $autodiscover = new Zend_Soap_AutoDiscover();
420 // Default is 'use' => 'encoded' and
421 // 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
422 $autodiscover->setOperationBodyStyle(
423 array('use' => 'literal',
424 'namespace' => 'http://framework.zend.com')
427 // Default is 'style' => 'rpc' and
428 // 'transport' => 'http://schemas.xmlsoap.org/soap/http'
429 $autodiscover->setBindingStyle(
430 array('style' => 'document',
431 'transport' => 'http://framework.zend.com')
434 $autodiscover->addFunction('myfunc1');
435 $autodiscover->handle();