Problems with nuSOAP on my first ever API att


  • Anonymous

    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:

    Here is the server code:

    function getStockQuote($symbol) {
        $query = "SELECT stock_price FROM stockprices "
               . "WHERE stock_symbol = '$symbol'";
        $result = mysql_query($query);
        $row = mysql_fetch_assoc($result);
        return $row['stock_price'];
    $server = new soap_server();
    $server->configureWSDL('stockserver', 'urn:stockquote');
                    array('symbol' => 'xsd:string'),
                    array('return' => 'xsd:decimal'),
                          ? $HTTP_RAW_POST_DATA : '';

    And here is the client code:

    $c = new soapclient('');
    $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(''); I do not get the 500, but a message that the function 'call' is not available…

    Any help much appreciated.

  • Scott Nichol
    Scott Nichol

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

    $c = new soapclient('', '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.