Not getting response using SOAP and PHP

十年热恋 提交于 2019-12-12 01:32:23

问题


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.


回答1:


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

return $row['stock_price'];


来源:https://stackoverflow.com/questions/2887374/not-getting-response-using-soap-and-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!