Category Archives: Web Services

Main difference between soap and rest api


Main difference between soap and rest api


Main difference between soap and rest api

[table width=”100%” colwidth=”20|100|50″ colalign=”left|left|center|left|right”]
No, SOAP ,REST
1,SOAP stands for Simple Object Access Protocal, REST stands for Representational State Transfer Protocal
2,Protocal,Architecture
3,Slow{Needs More Bandwidth}, Fast{Needs Less Bandwidth} Because of Lightweight
4,Supports Xml Format data, Supports JSON Text Html etc format
5,Supports WS-Security which adds enterprise security features, Does’t Supports WSSecurity
6,SOAP Supports WS-AtomicTransaction, Does’t Supports WS-AtomicTransaction
7,Less Preferred , More Preferred

[/table]

Error: Code-SOAP-ENV:ClientError String: error in msg parsing: XML error parsing SOAP payload on line 1: Space requiredArray ( )

Error: Code-SOAP-ENV:ClientError String: error in msg parsing: XML error parsing SOAP payload on line 1: Space requiredArray ( )

If you are getting the above error code and error string in the client.php file while hitting the service in soap.

This Occurs when you call function and there is space in calling the server function :

Example


$response = $client ->call(' getUserData ');

it will produce the error. To fix it remove the space between the single quotes and the name of the function.

Correct way to call the function .


$response = $client ->call('getUserData');

How to install soap in php

Steps : How to install soap in php

Step 1 : Download soap library nusoap-for-php5 from the link :
http://sourceforge.net/projects/nusoap/?source=typ_redirect

Step 2 : unzip the nosoap in new folder “firstweb”.

Step 3 : Now Create two files server.php and client.php.

Step 4 : Inside the server.php Add the following code :



register('getUserData', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server# getUserData');

function getUserData ()
{
	$items = array();
    $con = mysql_connect('localhost','root','');
	mysql_select_db('mydb', $con);
	$sql = "SELECT * FROM users";
	$query = mysql_query($sql);
		   
	while($row = mysql_fetch_array($query)){

					$items [] = array(
											'id'=>$row['id'],
											'name'=>$row['name'],
											'email'=>$row['email'],
											'profile_image'=>$row['profile_image']
						);
	}
		  return $items;

}
/*
You can add more functions here as per the requirement for the database connection make a connection class and include it in header

*/

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server ->service($HTTP_RAW_POST_DATA);

?>

Now you have created the function on server.php file which will fetch data and return the response.

Step 5 : Add the following code in the client.php

call('getUserData');

if($client->fault)
{
                echo "Eroor: Code-".$client ->faultcode."";
}
else
{
                $result = $response;
				
}

print_r($result);
?>

Not Hit the client.php in url it will return the result.

Note: Client.php file is used for testing and development purpose.
All data which will be returned through the webservice will be in the form of the xml data set.