Problems with nuSOAP on my first ever API att

Help
Anonymous
2010-02-19
2013-06-06

  • Anonymous
    2010-02-19

    Hi there,

    I'ver tried to build my first API from a very basic example I saw online. Since it didn't work so well initially, I copied the exact code in the end, tried again, but no cigar. I'm not sure what could be wrong here, but I do get a server 500 message when I try to load the client.

    However, the API URL seems to work fine: http://dev.badgercomp.com/api/testapi.php

    Here is the server code:

    <?php
    function getStockQuote($symbol) {
        include('dbconnection.php');
    
        $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 code:

    <?php
    require('nusoap.php');
    $c = new soapclient('http://dev.badgercomp.com/api/testapi.php');
    $stockprice = $c->call('getStockQuote',
                  array('symbol' => 'ABC'));
    echo "The stock price for 'ABC' is $stockprice.";
    ?>
    

    This all seems easy enough, so I can't understand why it won't work. Any advice?

    //as an update: when I point the soap client to the wsdl ($c = new soapclient('http://dev.badgercomp.com/api/testapi.php?wsdl'); I do not get the 500, but a message that the function 'call' is not available…

    Any help much appreciated.

     
  • Scott Nichol
    Scott Nichol
    2010-04-26

    To use the WSDL from the client, the ctor must have the second parameter either true or 'wsdl', such as

    $c = new soapclient('http://dev.badgercomp.com/api/testapi.php?wsdl', 'wsdl');

    Your service function does

    return $row;

    I don't use mysql, but is $row really a decimal value?  Your WSDL claims you return a decimal value.