<!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>Exposing a Service Component as a Web service</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.nonscascript.html">Locating and calling services from a script which is not an SCA Component</a></div> <div class="next" style="text-align: right; float: right;"><a href="sca.examples.deploy.html">Deploying an SCA component</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.exposing-webservice" class="section"> <h2 class="title"> Exposing a Service Component as a Web service </h2> <p class="para"> SCA for PHP can generate WSDL from the annotations within a service component, so that it can be easily deployed and exposed as a Web service. To provide SCA with the information it needs to generate the WSDL, it is necessary to add the annotation @binding.soap under the @service annotation and to specify the parameters and return values of the methods using the @param and @return annotations. These annotations will be read when WSDL is generated, and the order and types of the parameters determine the contents of the <schema> section of the WSDL. </p> <p class="para"> SCA for PHP always generates document/literal wrapped WSDL for components that are exposing a Web service. Note that this does not stop components from consuming Web services which are not SCA components and which are documented with WSDL written in a different style. </p> <p class="para"> The scalar types which can be used in the @param annotation are the four common PHP scalar types: boolean, integer, float and string. These are simply mapped to the XML schema types of the same name in the WSDL. The example below, which is a trivial implementation of the StockQuote service that the ConvertedStockQuote component calls, illustrates string and float types. </p> <p class="para"> <div class="example" id="example-5302"> <p><strong>Example #1 StockQuote Service </strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #007700">include </span><span style="color: #DD0000">"SCA/SCA.php"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/**<br /> * Scaffold implementation for a remote StockQuote Web service.<br /> *<br /> * @service<br /> * @binding.soap<br /> *<br /> */<br /></span><span style="color: #007700">class </span><span style="color: #0000BB">StockQuote </span><span style="color: #007700">{<br /><br /> </span><span style="color: #FF8000">/**<br /> * Get a stock quote for a given ticker symbol.<br /> *<br /> * @param string $ticker The ticker symbol.<br /> * @return float The stock quote.<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">) {<br /> return </span><span style="color: #0000BB">80.9</span><span style="color: #007700">;<br /> }<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> WSDL much like the following (though with a service location other than 'localhost', probably) would be generated from this service: </p> <p class="para"> <div class="example" id="example-5303"> <p><strong>Example #2 Generated WSDL </strong></p> <div class="example-contents"> <div class="xmlcode"><pre class="xmlcode"><?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xsi:type="tDefinitions" xmlns:tns2="http://StockQuote" xmlns:tns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns3="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" targetNamespace="http://StockQuote"> <types> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://StockQuote"> <xs:element name="getQuote"> <xs:complexType> <xs:sequence> <xs:element name="ticker" 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> <message name="getQuoteRequest"> <part name="getQuoteRequest" element="tns2:getQuote"/> </message> <message name="getQuoteResponse"> <part name="return" element="tns2:getQuoteResponse"/> </message> <portType name="StockQuotePortType"> <operation name="getQuote"> <input message="tns2:getQuoteRequest"/> <output message="tns2:getQuoteResponse"/> </operation> </portType> <binding name="StockQuoteBinding" type="tns2:StockQuotePortType"> <operation name="getQuote"> <input> <tns3:body xsi:type="tBody" use="literal"/> </input> <output> <tns3:body xsi:type="tBody" use="literal"/> </output> <tns3:operation xsi:type="tOperation" soapAction=""/> </operation> <tns3:binding xsi:type="tBinding" transport="http://schemas.xmlsoap.org/soap/http" style="document"/> </binding> <service name="StockQuoteService"> <port name="StockQuotePort" binding="tns2:StockQuoteBinding"> <tns3:address xsi:type="tAddress" location="http://localhost/StockQuote/StockQuote.php"/> </port> </service> </definitions> <!-- this line identifies this file as WSDL generated by SCA for PHP. Do not remove --></pre> </div> </div> </div> </p> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.nonscascript.html">Locating and calling services from a script which is not an SCA Component</a></div> <div class="next" style="text-align: right; float: right;"><a href="sca.examples.deploy.html">Deploying an SCA component</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>