eZ Community » Forums » Developer » Creating Web Service in Php using...
expandshrink

Creating Web Service in Php using nusoap Error

Creating Web Service in Php using nusoap Error

Wednesday 24 July 2013 9:32:35 am - 1 reply

Hi all,
I am learning php.
I have created Web Service in php using nusoap.dll. I have written price test method it's return integer it's working fine, but when I fetch database, to return array it's returning error. I had tried to resolve the error, but it's still giving error.
Could you tell me where I went wrong.
my php code is:
//service.php

<?php

/**
* @author
* @copyright 2013
*/

require 'lib/nusoap.php';
require 'functions.php';

$server = new nusoap_server();
$server -> configureWSDL('WS'.'urn:WS');
$server -> register(
                    "price", //name of the function
                    array("name" => 'xsd:string'), //inputs
                    array("return" => 'xsd:inter')  //outputs
                    );

$server -> register(
                    "ReadBooks", //name of the function
                    array("productid" => 'xsd:inter'), //inputs
                    array("return" => 'xsd:unbounded')  //outputs
                    );
/**
* $server -> register(
*                     "countbooks", //name of the function
*                     array(), //inputs
*                     array()  //outputs
*                     );
*/
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

?>
//functions.php

<?php

/**
* @author
* @copyright 2013
*/

function price($name){
    $details=array('abc'=>100,
                   'xyz'=>200);
    foreach($details as $n => $p){
        if($name==$n){
            $prices = $p;
        }
    }
    return $prices;
}

function ReadBooks($productid)
{
    mysql_connect("localhost","root",""blunk.gif Emoticon or die(mysql_error());
    mysql_select_db("Sample"blunk.gif Emoticon or die(mysql_error());
    $myQuery='Select * from php_shop_products where product_id='.$productid;
    $results = mysql_query($myQuery);
    if($results===false){
        return die($myQuery."<br/><br/>".mysql_error());
    }
    else{
        return $results;
    }
    return die(mysql_error());
}

/*$results =ReadBooks(1);

while($row =mysql_fetch_array($results)){
    echo $row['name'];
}*/

?>
//client.php

<?php

/**
* @author
* @copyright 2013
*/

require 'lib/nusoap.php';

$client = new nusoap_client(";" title="http://localhost:8080/myfiles/examples/WS/service.php?wsdl"blunk.gif Emoticon;">http://localhost:8080/myfiles/examples/WS/service.php?wsdl"blunk.gif Emoticon;
$book_name="xyz";
$prices=$client->call('price',array("name"=>"$book_name"blunk.gif Emoticon);

echo $prices . '<br/>';

$productid=1;
$results=$client->call('ReadBooks',array("productid"=>$productid));

while($row =mysql_fetch_array($results)){
    echo $row['name'];
}


?>
it's returning error:
First function result : 200 //success
//second function error
Fault:
Array
(
[faultcode] => SOAP-ENV:Server
[faultactor] =>
[faultstring] => unable to serialize result
[detail] =>
)
Could you tell me where I went wrong.
Thanks in advance..........

Modified on Wednesday 24 July 2013 10:57:48 am by Manoj T

Thursday 25 July 2013 2:02:21 pm

Hello.

 

Are you sure that you are posting in the correct forum? It does not seem that your webservice is in any way related to ezpublish...

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from