使用 SOAP 和 PHP 未获得响应
我正在使用 PHP5 和 NuSOAP - PHP 的 SOAP 工具包。 我使用下面的代码创建了服务器:
<?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 未作为价格打印。
I'm using PHP5 and NuSOAP - SOAP Toolkit for PHP.
I created the server using the code below:
<?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);
?>
The client has the following code:
<?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.";
?>
The database was created using the code below:
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');
When I run the client the result I get is this:
The stock price for 'ABC' is .
75.00 is not being printed as the price.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
函数中缺少返回方法,也许这就是问题所在。
the return method is missing in the function, maybe that is the problem.