没有使用SOAP和PHP获得响应

时间:2010-05-22 07:59:05

标签: php soap nusoap

我正在使用PHP5和NuSOAP - SOAP Toolkit for PHP。 我使用以下代码创建了服务器:

<?php
function getStockQuote($symbol) {
mysql_connect('localhost','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);
echo $row['stock_price'];
}

$a=require('lib/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('lib/nusoap.php');
$c = new soapclientNusoap('http://localhost/stockserver.php?wsdl');
$stockprice = $c->call('getStockQuote',
          array('symbol' => 'ABC'));
echo "The stock price for 'ABC' is $stockprice.";

?>

使用以下代码创建数据库:

CREATE TABLE `stockprices` (
`stock_id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`stock_symbol` CHAR( 3 ) NOT NULL ,
`stock_price` DECIMAL(8,2) NOT NULL ,
PRIMARY KEY ( `stock_id` )
);
INSERT INTO `stockprices` VALUES (1, 'ABC', '75.00');
INSERT INTO `stockprices` VALUES (2, 'DEF', '45.00');
INSERT INTO `stockprices` VALUES (3, 'GHI', '12.00');
INSERT INTO `stockprices` VALUES (4, 'JKL', '34.00');

当我运行客户端时,我得到的结果是:

  

'ABC'的股价是。

75.00未打印出价格。

1 个答案:

答案 0 :(得分:1)

函数中缺少return方法,可能就是问题。

return $row['stock_price'];