📄 sca.examples.nonscascript.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Locating and calling services from a script which is not an SCA Component</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div 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 <a href="function.sca-getservice.html" class="function">SCA::getService()</a> static method to obtain a proxy for a service, whether local or remote. The <b>getService()</b> 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 <b>getService()</b> method as follows: </p> <p class="para"> <div class="example"> <p><b>Example #1 Obtaining a proxy using getService </b></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"> <p><b>Example #2 Making calls on the proxy </b></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 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -