简体   繁体   中英

creating a simple php web service using nusoap

i want to display the server's data in multiple rows to the client side. The current implementation shows only one row ie value of 'ABC' to client Here is the server side:

<?php
    function getStockQuote($symbol) {

        mysql_connect('server','user','pass');
        mysql_select_db('test');
        $query = "SELECT stock_price FROM stockprices "
               . "WHERE stock_symbol = '$symbol'";
        $result = mysql_query($query);

        $row = mysql_fetch_assoc($result);
        return $row['stock_price'];
    }

    require('nusoap.php');

    $server = new soap_server();

    $server->configureWSDL('stockserver', 'urn:stockquote');

    $server->register("getStockQuote",
                    array('symbol' => 'xsd:string'),
                    array('return' => 'xsd:decimal'),
                    'urn:stockquote',
                    'urn:stockquote#getStockQuote');

    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
                          ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
?>

And here is the client side:

<?php
    require_once('nusoap.php');

    $c = new soapclient('http://localhost/stockserver.php');

    $stockprice = $c->call('getStockQuote',
              array('symbol' => 'ABC'));

    echo "The stock price for 'ABC' is $stockprice.";

?>

You must specify an WSDL as endpoint, so change the endpoint with the wsdl, and need to call to your method ( call method doesn't exist on your server)

My client code that i test and works:

<?php
require_once('nusoap.php');

$c = new soapclient('http://localhost/stockserver.php?wsdl');

$stockprice = $c->getStockQuote('ABC');
echo "The stock price for 'ABC' is $stockprice.";

?>

And please stop using deprecated mysql_* functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM