Re: [SOAP] PHP SOAP - Extreme newbie questions :/
[email protected] (lmhelp2) Fri, 2 Apr 2010 01:47:08 -0700 (PDT)
| Newsgroups | php.soap |
|---|---|
| Message-ID | <[email protected]> |
[
- First: answer to John see below.
- Richard, I saw your post and I am trying now to get it work.
Thanks.
- Thanks to zippy1981 too.
- Nota: I don't know why but there are some posts missing on the
thread...
]
Hi John,
Thank you for your contribution.
I've tested your code and it works:
- with the dummy data,
- and with the database data.
So, folks, download and test:
http://www.steelesoftconsulting.com/code/stockquote.zip
you'll have a working code!
There are a lot of posts about this example on the web...
I tried to see what was wrong with "my" copy of the code.
I post here the version that works now
(I've removed the comments so that it's very compact):
=================================================================
soap_server.php
=================================================================
<?php
function getStockQuote($symbol)
{
// Set "user and "password" for your system.
mysql_connect('localhost', 'user', 'password');
mysql_select_db('soap_tutorial');
$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);
?>
=================================================================
soap_client.php
=================================================================
<?php
require("nusoap.php");
// Set "SERVER_URL" for your system.
define('SERVER_URL', 'http://localhost/soap/soap_server.php');
$client = new nusoap_client(SERVER_URL. '?wsdl', true);
$symbol = 'ABC';
if(isset($_GET['symbol']) && !empty($_GET['symbol']))
$symbol = $_GET['symbol'];
$params = array('symbol' => $symbol);
$result = $client->call('getStockQuote', $params);
echo "=====================================================";
echo "<br />";
echo "The stock price for \"" . $symbol . "\" is " . $result . ".";
echo "<br />";
echo "=====================================================";
echo "<br />";
?>
=================================================================
In your HTTP server root directory:
-- create a directory "soap"
-- and put in it the three files:
- soap_server.php
- soap_client.php
- nusoap.php
=================================================================
You can then type in your browser:
- either: http://localhost/soap/soap_client.php
in which case, you'll get the following result:
=====================================================
The stock price for "ABC" is 66.12.
=====================================================
- or, for instance: http://localhost/soap/soap_client.php?symbol=JKL
in which case, you'll get the following result:
=====================================================
The stock price for "JKL" is 34.
=====================================================
=================================================================
I think that my problems came from:
1) The MySQL extension for PHP wasn't enabled on my computer:
To solve that problem:
uncomment in "php.ini" (PHP 5) the following line:
-----------------------------------------------------------------
extension=php_mysql.dll
-----------------------------------------------------------------
This is probably the reason why I got some errors.
2) The following lines were missing in my client code:
-----------------------------------------------------------------
$symbol = 'ABC';
if(isset($_GET['symbol']) && !empty($_GET['symbol']))
$symbol = $_GET['symbol'];
-----------------------------------------------------------------
This is probably the reason why the result was empty!
Thanks a lot.
Sincerely,
--
Lmhelp
--
View this message in context: http://old.nabble.com/PHP-SOAP---Extreme-newbie-questions-%3A--tp28095423p28116954.html
Sent from the Php - Soap mailing list archive at Nabble.com.