<!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>Locating and calling services from a script which is not an SCA Component</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="sca.examples.calling.html">Calling another Service Component</a></div> <div class="next" style="text-align: right; float: right;"><a href="sca.examples.exposing-webservice.html">Exposing a Service Component as a Web service</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.nonscascript" class="section"> <h2 class="title">Locating and calling services from a script which is not an SCA Component </h2> <p class="para"> SCA components obtain proxies for other components or services as instance variables annotated with @reference, but this is not possible for a script that is not itself also a component. A client script which is not a component must use the <span class="function"><a href="sca.getservice.html" class="function">SCA::getService()</a></span> static method to obtain a proxy for a service, whether local or remote. The <span class="function"><strong>getService()</strong></span> method takes a URI as the argument. Typically this is the location of a local PHP script containing a component, or of a wsdl file, and is used in exactly the same way as the targets of the @binding annotations described in the previous section: that is, relative URIs are resolved against the location of the client script and not against the PHP include_path or current working directory. </p> <p class="para"> For example, a script that needed to obtain proxies for the ExchangeRate and StockQuote services but was not a component would use the <span class="function"><strong>getService()</strong></span> method as follows: </p> <p class="para"> <div class="example" id="example-5300"> <p><strong>Example #1 Obtaining a proxy using getService </strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$exchange_rate </span><span style="color: #007700">= </span><span style="color: #0000BB">SCA</span><span style="color: #007700">::</span><span style="color: #0000BB">getService</span><span style="color: #007700">(</span><span style="color: #DD0000">'../ExchangeRate/ExchangeRate.php'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$stock_quote </span><span style="color: #007700">= </span><span style="color: #0000BB">SCA</span><span style="color: #007700">::</span><span style="color: #0000BB">getService</span><span style="color: #007700">(</span><span style="color: #DD0000">'../StockQuote/StockQuote.wsdl'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> <p class="para"> Methods on services can then be called on the returned proxy, just as they can in a component. </p> <p class="para"> <div class="example" id="example-5301"> <p><strong>Example #2 Making calls on the proxy </strong></p> <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">$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">$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 /></span><span style="color: #0000BB">?></span> </span> </code></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.calling.html">Calling another Service Component</a></div> <div class="next" style="text-align: right; float: right;"><a href="sca.examples.exposing-webservice.html">Exposing a Service Component as a Web service</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>