Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Creating Web Service in Php using nusoap Error

General discussions related to php

Moderators: macek, egami, gesf

Creating Web Service in Php using nusoap Error

Postby manojt » Tue Jul 23, 2013 11:38 pm

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","") or die(mysql_error());
mysql_select_db("Sample") 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("http://localhost:8080/myfiles/examples/WS/service.php?wsdl");
$book_name="xyz";
$prices=$client->call('price',array("name"=>"$book_name"));

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..........:?
manojt
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Jul 23, 2013 11:34 pm

Re: Creating Web Service in Php using nusoap Error

Postby johnj » Wed Jul 24, 2013 8:26 am

for your second function, inside the function, print this query....$myQuery='Select * from php_shop_products where product_id='.$productid; and then run it against your database using a client like phpmyadmin and make sure that this query will return something. Looks like it is returning nothing or '0'.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron