Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am learning php.

I have created Web Service in php using nusoap. I have written a method for fetch database results, 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:

//server.php

PHP
<?php

require_once("nuSOAP/lib/nusoap.php");
require_once("Classes/Connection.class.php");
require_once("Classes/Customer.class.php");


// create a new soap server
$server = new soap_server();
// configure our WSDL
$server->configureWSDL("CustomerLookup","urn:CustomerLookup");
$server ->register('GetAllCustomers', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server# GetAllCustomers');
function GetAllCustomers()
{
	$database = new Connection();
			
	$result = $database->runQuery("SELECT * FROM customers");
	$num = mysql_num_rows($result);
	
	if($num == 0)
	{
		return "";
	}
	else
	{
		$tempArray = array();
		
		for($i=0;$i<$num;$i++)
		{
            $items [] = array( 'id'=>$row['id'],'phonenumber'=>$row['phonenumber'],'businessname'=>$row['businessname']);
		}
		return $items;
	}
}             
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($POST_DATA);                
exit();
?>


//Client.php

PHP
<?php

require_once("nuSOAP/lib/nusoap.php");
$client = new nusoap_client("http://localhost:8080/myfiles/customerswebservice/Client.php?wsdl");

$response = $client ->call(' GetAllCustomers ');
if ($client->fault) {
	echo '<h2>Fault</h2>';
	print_r($response);} else {
	// Check for errors
	$err = $client->getError();
	if ($err) {
		// Display the error
		echo '<h2>Error</h2>' . $err';
	} else {
	   }
       }
//var_dump($response);

?>

my error is:

Fault Error:
Array
(
    [faultcode] => SOAP-ENV:Client
    [faultactor] => 
    [faultstring] => error in msg parsing:
XML error parsing SOAP payload on line 1: Space required
    [detail] => 
)

could you tell me where I went wrong?

thanks in advance.........
Posted
Updated 25-Jul-13 19:52pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900