我想将多行的服务器数据显示给客户端。当前实现仅显示一行,即客户端的“ABC”值 这是服务器端:
<?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);
?>
这是客户方:
<?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.";
?>
答案 0 :(得分:1)
您必须将WSDL指定为端点,因此使用wsdl更改端点,并且需要调用您的方法(服务器上不存在call
方法)
我测试并运行的客户端代码:
<?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.";
?>
请停止使用已弃用的mysql_ *函数