Locating and calling services from a script which is not an SCA Component

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 SCA::getService() static method to obtain a proxy for a service, whether local or remote. The getService() 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.

For example, a script that needed to obtain proxies for the ExchangeRate and StockQuote services but was not a component would use the getService() method as follows:

Example #1 Obtaining a proxy using getService

<?php
$exchange_rate 
SCA::getService('../ExchangeRate/ExchangeRate.php');
$stock_quote   SCA::getService('../StockQuote/StockQuote.wsdl');
?>

Methods on services can then be called on the returned proxy, just as they can in a component.

Example #2 Making calls on the proxy

<?php
$quote  
$stock_quote->getQuote($ticker);
$rate   $exchange_rate->getRate($currency);
?>

相关文章
php eventhttpconnection sets the ip address from which http connections are madephp eventhttpconnection sets the local port from which connections are madephp gettext 函数 specify the character encoding in which the messages from the domain message catalog will be returnedphp grapheme 函数 function to extract a sequence of default grapheme clusters from a text buffer which must be encoded in utf 8php maxdb 函数 returns the sqlstate error from previous maxdb operationphp ncurses 函数 remove panel from the stack and delete it but not the associated window php socket 函数 receives data from a socket whether or not it is connection orientedphp stream 函数 receives data from a socket connected or notphp mongocommandcursor checks if there are results that have not yet been sent from the databasephp mongocursor checks if there are results that have not yet been sent from the databasephp mongocursorinterface checks if there are results that have not yet been sent from the databasephp 范例 calling another service componentphp 范例 deploying an sca componentphp 范例 locating and calling services from a script which is not an sca componentphp 范例 obtaining the wsdl for an sca component offering a service as a web servicephp solrquery returns the treshold frequency at which words will be ignored which do not occur in at least this many docsphp solrquery returns the field from which the terms are retrievedphp solrquery returns whether or not to include the upper bound term in the result setphp solrquery sets the factor by which the regex fragmenter can stray from the ideal fragment sizephp swoole buffer release the memory to os which is not used by the memory buffer.
关注编程学问公众号