<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Understanding how the WSDL is generated</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.obtaining-wsdl.html">Obtaining the WSDL for an SCA component offering a Service as a Web service</a></div> <div class="next" style="text-align: right; float: right;"><a href="sca.examples.structures.html">Working with Data Structures</a></div> <div class="up"><a href="sca.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="sca.examples.understanding-wsdl" class="section"> <h2 class="title"> Understanding how the WSDL is generated </h2> <p class="para"> SCA for PHP generates WSDL for components which contain an @binding.soap annotation after the @service annotation. To generate WSDL, the SCA runtime reflects on the component and examines the @param and @return annotations for each public method, as well as any @types annotations within the component. The information from the @param and @return annotations is used to build the <types> section of the WSDL. Any @types annotations which specify a separate schema file will result in an <import> element for that schema within the WSDL. </p> <div class="section" id="sca.examples.understanding-wsdl.location"> <h2 class="title"> Location attribute of the <service> element</h2> <p class="para"> At the bottom of the WSDL is the <service> element which uses the location attribute to identify the URL of the service. For example this might look as follows: </p> <p class="para"> <div class="example" id="example-5305"> <p><strong>Example #1 location attribute </strong></p> <div class="example-contents"> <div class="xmlcode"><pre class="xmlcode"><service name="ConvertedStockQuote" ... location="http://localhost/ConvertedStockQuote/ConvertedStockQuote.php"/></pre> </div> </div> </div> </p> <p class="para"> Note that this location is relative to the document root of the web server, and cannot be worked out in advance. It can only be worked out once the component is in its proper place under a running web server, when the hostname and port can be known and placed in the WSDL. Detail from the URL that requests the WSDL is used, so for example if the WSDL is generated in response to a request to http://www.example.com:1111/ConvertedStockQuote/ConvertedStockQuote.php?wsdl, a location of http://www.example.com:1111/ConvertedStockQuote/ConvertedStockQuote.php is what will be inserted into the location attribute in the WSDL. </p> </div> <div class="section" id="sca.examples.understanding-wsdl.positional-parameters"> <h2 class="title">Document/literal wrapped WSDL and positional parameters</h2> <p class="para"> SCA for PHP generates WSDL in the document/literal wrapped style. This style encloses the parameters and return types of a method in 'wrappers' which are named after the corresponding method. The <types> element at the top of the WSDL defines each of these wrappers. If we consider the <span class="function"><strong>getQuote()</strong></span> method of the ConvertedStockQuote example: </p> <p class="para"> <div class="example" id="example-5306"> <p><strong>Example #2 method with two arguments </strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> </span><span style="color: #FF8000">/**<br /> * Get a stock quote for a given ticker symbol in a given currency.<br /> *<br /> * @param string $ticker The ticker symbol.<br /> * @param string $currency What currency to convert the value to.<br /> * @return float The stock value is the target currency.<br /> */<br /> </span><span style="color: #007700">function </span><span style="color: #0000BB">getQuote</span><span style="color: #007700">(</span><span style="color: #0000BB">$ticker</span><span style="color: #007700">, </span><span style="color: #0000BB">$currency</span><span style="color: #007700">)<br /> {<br /> </span><span style="color: #0000BB">$quote </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">stock_quote</span><span style="color: #007700">-></span><span style="color: #0000BB">getQuote</span><span style="color: #007700">(</span><span style="color: #0000BB">$ticker</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$rate </span><span style="color: #007700">= </span><span style="color: #0000BB">$this</span><span style="color: #007700">-></span><span style="color: #0000BB">exchange_rate</span><span style="color: #007700">-></span><span style="color: #0000BB">getRate</span><span style="color: #007700">(</span><span style="color: #0000BB">$currency</span><span style="color: #007700">);<br /> return </span><span style="color: #0000BB">$rate </span><span style="color: #007700">* </span><span style="color: #0000BB">$quote</span><span style="color: #007700">;<br /> }<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> The WSDL generated to define this method will name both the method and the parameters, and give an XML schema type for the parameters. The types section of the WSDL looks like this: </p> <p class="para"> <div class="example" id="example-5307"> <p><strong>Example #3 types section illustrating named parameters </strong></p> <div class="example-contents"> <div class="xmlcode"><pre class="xmlcode"><types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ConvertedStockQuote"> <xs:element name="getQuote"> <xs:complexType> <xs:sequence> <xs:element name="ticker" type="xs:string"/> <xs:element name="currency" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getQuoteResponse"> <xs:complexType> <xs:sequence> <xs:element name="getQuoteReturn" type="xs:float"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> </types></pre> </div> </div> </div> </p> <p class="para"> The SCA run-time has special processing to handle how positional parameter lists in the interface are converted to XML containing named parameters in the soap request, and then back to positional parameter lists again. To see why this matters, consider how a PHP script which used a different interface to make a SOAP call would need to construct the parameter list. A PHP script using the PHP SoapClient, for example, would need to pass the SoapClient a single parameter giving the values for "ticker" and "currency", perhaps as an associative array. To insist that SCA components construct parameter lists to make Web service calls in this way would be to make local and remote calls look different, so a different approach is needed. </p> <p class="para"> When SCA generates WSDL for an SCA component it includes a comment in the WSDL which marks that WSDL as being the interface for an SCA component. In this case, when one SCA component calls another through a Web service, the SCA runtime on the calling end takes the positional parameter list from the call and assigns the values one by one to the named elements in the soap message. For example a call to the <span class="function"><strong>getQuote()</strong></span> method defined above that passes the values 'IBM' and 'USD' and looks like this: </p> <p class="para"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /> $quote </span><span style="color: #007700">= </span><span style="color: #0000BB">$remote_service</span><span style="color: #007700">-></span><span style="color: #0000BB">getQuote</span><span style="color: #007700">(</span><span style="color: #DD0000">'IBM'</span><span style="color: #007700">,</span><span style="color: #DD0000">'USD'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </p> <p class="para"> will result in a soap message containing the following: </p> <p class="para"> <div class="example-contents"> <div class="xmlcode"><pre class="xmlcode"><getQuote> <ticker>IBM</ticker> <currency>USD</currency> </getQuote></pre> </div> </div> </p> <p class="para"> On the service-providing end, the SCA run-time takes the parameters one by one from the soap message and forms a positional parameter list from them, re-forming the argument list ('IBM','USD'). </p> <div class="caution"><strong class="caution">Caution</strong> <p class="para"> At both ends the SCA runtime relies on the order in which the parameters appear in the soap message being the same as that in the target method's parameter list. This is ultimately determined by the order of the @param annotations: this determines the order in which the parameters appear in the WSDL and thereby the order in which they appear in the soap message. Therefore it is essential that the order of the @param annotations matches that of the parameters in the method's parameter list. </p> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.obtaining-wsdl.html">Obtaining the WSDL for an SCA component offering a Service as a Web service</a></div> <div class="next" style="text-align: right; float: right;"><a href="sca.examples.structures.html">Working with Data Structures</a></div> <div class="up"><a href="sca.examples.html">Examples</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>