使用 SOAP 和 PHP 未获得响应

发布于 2024-09-02 16:57:31 字数 1688 浏览 7 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

关于从前 2024-09-09 16:57:31

函数中缺少返回方法,也许这就是问题所在。

return $row['stock_price'];

the return method is missing in the function, maybe that is the problem.

return $row['stock_price'];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文