sca-php-examples-php-nonscascript-3

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

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

    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);
    ?>