3707

Not getting response using SOAP and PHP

Question:

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:

<blockquote>

The stock price for 'ABC' is .

</blockquote>

75.00 is not being printed as the price.

Answer1:

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

return $row['stock_price'];

Recommend

  • how to solve the Deprecated problem For SEO
  • Stripping HTML from jQuery load() result
  • PHP/Mysql array_pop missing first value
  • How to JSON data using $.getJSON from a php file?
  • Opening Info Window when clicking a table row
  • Unity touch input for Rolling Sky x axis control
  • MySQL: Difference between `… ADD INDEX(a); … ADD INDEX(b);` and `… ADD INDEX(a,b);`?
  • Python Tkinter after event OOPS implementation
  • Dynamic ranges again - once more, with text strings
  • insert radio value multiple data codeigniter in database to one row?
  • What's the syntax to inherit documentation from another indexer?
  • Drawing a Path in XAML (with binding) vs. C#. One works, one doesn't
  • ggplot2: make the points on the line a darker color than the line color
  • Add dynamic data to line chart from mysql database with highcharts
  • Row to Column conversion in Talend
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • PLSQL: Get number of records updated vs inserted when a merge statement is used
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • Query to find the duplicates between the name and number in table
  • rspec simple example getting error on request variable in integration test
  • gspread or such: help me get cell coordinates (not value)
  • Stop Bash Script if Hive Fails
  • error importing numpy
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • MongoDb aggregation
  • How to attach a node.js readable stream to a Sendgrid email?
  • Very simple C++ DLL that can be called from .net
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Spray.io: When (not) to use non-blocking route handling?
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • align graphs with different xlab
  • Unanticipated behavior
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • AngularJs get employee from factory
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Can't mass-assign protected attributes when import data from csv file
  • Unable to use reactive element in my shiny app