Barry62
asked on
Web Service is giving me a 404 page
I am using nusoap to create a PHP web service. I coded the server on one website, and the client on another. When I call the server from the client, I get a 404 error. Any ideas?
Server:
Client:
Server:
<?
//call library
require_once ('../nusoap/lib/nusoap.php');
include('Calls.php');
include('currentSeason.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('getCurrentSeason');
// create the function
function getCurrentSeason()
{
return $arrEntireSeason;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
Client:
<?
require_once ('../nusoap/lib/nusoap.php');
$client = new soapclient('http://www.tltjc.org/server_CurrentSeason.php');
$response = $client->call('getCurrentSeason');
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode.")</p>";
echo "String: ".$client->faultstring;
}
else
{
$r = $response;
$count = count($r);
?>
<table border="1">
<tr>
<th>Title</th>
<th>Author</th>
<th>Director</th>
</tr>
<?
for($i=0;$i<=$count-1;$i++){
?>
<tr>
<td><?=$r[$i]['showname']?></td>
<td><?=$r[$i]['credits']?></td>
<td><?=$r[$i]['director']?></td>
</tr>
<?
}
?>
</table>
<?
}
?>
ASKER
I'll look into it.
ASKER
I don't really want to use a framework for this. I already have a PHP website built. I just want a service to call. I found an article by Arun Kumar Sekar regarding ESTful services that uses rest.inc.php, which I assume he also developed. Where would I find that?
This may be a lot simpler than you think! You don't need a framework. A RESTful web service is just like a web page. The consumer of the service simply reads the response from a URL. The provider of the service writes the output to the browser output stream. To see how simple this is, click on these links (runs the script posted above). Use "view source" to look at the output.
http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Ray
http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Error
http://laprbass.com/RAY_REST_get_last_name.php?key=Wrong&resp=XML&name=Ray
I looked at http://www.9lessons.info/2012/05/create-restful-services-api-in-php.html and I am not sure if that is the article you're referring to, but I can tell you that it appears to be enormously elaborate and full of non-value-added code. If you stick to a simple service you should be OK.
http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Ray
http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Error
http://laprbass.com/RAY_REST_get_last_name.php?key=Wrong&resp=XML&name=Ray
I looked at http://www.9lessons.info/2012/05/create-restful-services-api-in-php.html and I am not sure if that is the article you're referring to, but I can tell you that it appears to be enormously elaborate and full of non-value-added code. If you stick to a simple service you should be OK.
ASKER
I'm starting to understand your code example. What if I wanted to return multiple values from my database (i.e. several records?)
You would return these values in either an XML document or a JSON string. Probably the underlying structure would be an array of objects (with one object representing one row from the results set). The properties of each object would be the values from the query. The names of the properties would be the column names or the query-assigned names.
XML can use almost any encoding. JSON requires UTF-8. If it's all ascii character material, there are no UTF-8 collisions below code point 128. If you have accented characters, the Euro, etc., you will need to be careful about using consistent UTF-8 encoding from top to bottom.
XML can use almost any encoding. JSON requires UTF-8. If it's all ascii character material, there are no UTF-8 collisions below code point 128. If you have accented characters, the Euro, etc., you will need to be careful about using consistent UTF-8 encoding from top to bottom.
ASKER
OK, I'm better at XML than JSON, but I'm not that great with XML, either. Would this be a good structure to use?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<shows>
<show>
<showname></showname>
<credits></credits>
<director></director>
</show>
</shows>
Then how would I parse the XML into an array from my client?
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<shows>
<show>
<showname></showname>
<credits></credits>
<director></director>
</show>
</shows>
Then how would I parse the XML into an array from my client?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent! I got it working. Thanks, Ray!
Thanks for the points - you will be MUCH happier with this than with SOAP. ~Ray
https://en.wikipedia.org/wiki/Representational_State_Transfer
https://en.wikipedia.org/wiki/Roy_Fielding
You can see an example of a RESTful web service here:
Open in new window
HTH, ~Ray