简体   繁体   English

使用nusoap创建一个简单的PHP Web服务

[英]creating a simple php web service using nusoap

i want to display the server's data in multiple rows to the client side. 我想在客户端向多行显示服务器数据。 The current implementation shows only one row ie value of 'ABC' to client Here is the server side: 当前的实现仅显示一行,即客户端的'ABC'值。这是服务器端:

<?php
    function getStockQuote($symbol) {

        mysql_connect('server','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);
        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);
?>

And here is the client side: 这是客户端:

<?php
    require_once('nusoap.php');

    $c = new soapclient('http://localhost/stockserver.php');

    $stockprice = $c->call('getStockQuote',
              array('symbol' => 'ABC'));

    echo "The stock price for 'ABC' is $stockprice.";

?>

You must specify an WSDL as endpoint, so change the endpoint with the wsdl, and need to call to your method ( call method doesn't exist on your server) 您必须将WSDL指定为端点,因此使用wsdl更改端点,并需要调用您的方法(服务器上不存在call方法)

My client code that i test and works: 我测试并工作的客户代码:

<?php
require_once('nusoap.php');

$c = new soapclient('http://localhost/stockserver.php?wsdl');

$stockprice = $c->getStockQuote('ABC');
echo "The stock price for 'ABC' is $stockprice.";

?>

And please stop using deprecated mysql_* functions 并且请停止使用不推荐使用的mysql_ *函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM