Trying to make a nusoap webservices example from ZEND work
Posted: Mon Nov 07, 2005 6:23 pm
I am trying to make an example from ZEND work.
There are basically two files
1. server file - taxCalc.php
2. client file - taxCalcClient.php
Function provided: Tax calculation
Function prototype: float taxCalc ($rate, $sub)
All nusoap files are loaded into a sub-directory nusoap from where the client file is running.
I provide codes below and the links to the files in action.
Can anyone find out where is the problem? I am sure that the function in the server side is not called.
The error it returns
Client file
Server file
There are basically two files
1. server file - taxCalc.php
2. client file - taxCalcClient.php
Function provided: Tax calculation
Function prototype: float taxCalc ($rate, $sub)
All nusoap files are loaded into a sub-directory nusoap from where the client file is running.
I provide codes below and the links to the files in action.
Can anyone find out where is the problem? I am sure that the function in the server side is not called.
The error it returns
Code: Select all
Code: Client
String: method '' not defined in serviceCode: Select all
<html>
<head>
<title>Tax calculator Client</title>
</head>
<body>
<h1>Tax calculated:</h1>
<?php
/**
* taxCalcClient.php
* An example PHP script which uses NuSOAP to access
* a tax calculator function.
*
* Created on August 7, 2002, 6:11 PM
* @author Sean Campbell
* @version 1.0
*/
/* Include the NuSOAP library. */
require_once('nusoap/nusoap.php');
/* Initialize the client's parameter list. */
$param = array('rate' => $_GET['rate'],
'sub' => $_GET['sub']
);
print_r($param);
/* Create a new client by providing the endpoint to the
* constructor. */
$client = new soapclient(
'http://testdomain.farvista.net/taxCalc.php'
);
/* Call the taxCalc() function, passing the parameter list. */
$response = $client->call('taxCalc', $param);
/* handle any SOAP faults. */
if ($client->fault) {
echo "FAULT: <p>Code: {$client->faultcode}<br />";
echo "String: {$client->faultstring}";
} else {
echo "$" . $response;
}
?>
</body>
</html>Code: Select all
<?php
/**
* taxCalc.php
* An example PHP script which uses NuSOAP to provide a
* tax calculator function.
*
* Created on August 7, 2002, 6:11 PM
* @author Sean Campbell
* @version 1.0
*/
/* Include the NuSOAP library. */
require_once('nusoap/nusoap.php');
/* Create a new SOAP server instance. */
$server = new soap_server;
/* Register the taxCalc function for publication. */
$server->register('taxCalc');
/**
* Calculates the total (including tax) for a purchase based on the
* rate and subtotal provided.
*
* @param string $rate The tax rate in percent.
* @param string $sub The subtotal for the purchase.
*
* @return float $total The total for the purchase.
*
* @author Sean Campbell
* @version 1.0
*/
function taxCalc ($rate, $sub)
{
if ($rate == '' || $rate <= 0) {
/* Return a SOAP fault indicating a negative or
* zero tax rate was transmitted. */
return new soap_fault(
'Client', '',
'Must supply a positive, non-zero tax rate.',''
);
}
if ($sub == '' || $sub <= 0) {
/* Return a SOAP fault indicating a negative or
* zero subtotal was transmitted. */
return new soap_fault(
'Client', '',
'Must supply a positive, non-zero subtotal.', ''
);
}
/* Return the generated total for the purchase. */
return (($rate / 100) * $sub) + $sub;
}
/* Begin the HTTP listener service and exit. */
$server->service($_SERVER['HTTP_RAW_POST_DATA']);
exit();
?>