Reputation: 625
I have created the gSOAP Calculator Service example found at: http://www.genivia.com/Products/gsoap/demos/index.html
I have my web service running as a deamon on my Solaris box.
Now I'm trying to use a php page to hit this new web service. I have been looking at http://www.php.net/manual/en/class.soapclient.php, and have tried to make an example, but have had no luck. Can someone please point me to an example of doing this? or show me the code for doing it?
I have spent two days looking at web sites and trying different things and am running out of time on my project. Thank you so much for your help.
fyi: I have my apache server set to port 7000.
<?php
function customError($errno, $errstr)
{
echo "<b>Error: </b> [$errno] $errstr";
}
set_error_handler("customError");
define("SOAP_ENCODED", 1);
define("SOAP_RPC", 1);
$options = array(
'compression'=>true,
'exceptions'=>false,
'trace'=>true,
'use' => SOAP_ENCODED,
'style'=> SOAP_RPC,
'location'=> "http://localhost:7000",
'uri' => "urn:calc"
);
echo "1";
$client = @new SoapClient(null, $options);
echo "2";
$args = array(2, 3);
$ret = $client->__soapCall("add", $args);
echo "3";
if (is_soap_fault($ret))
{
echo 'fault : ';
var_dump($client->__getLastRequest());
var_dump($client->__getLastRequestHeaders());
}
else
{
echo 'success : ';
print '__'.$ret.'__';
}
$client->ns__allAllowed();
?>
The web page does not return any errors.
Michael
Upvotes: 0
Views: 1518
Reputation: 2448
At the top of the script:
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('display_startup_errors', true);
Some things to check:
?>
(You should just remove it)php /path/myscript.php
Upvotes: 1
Reputation: 2379
In the tutorial you mentioned written that Calc web service generates WSDL. WSDL is a file that describes all methods and types of web service. Keeping this in mind you can create SOAP client in PHP:
$client = new SoapClient('http://www.mysite.com/calc.wsdl',
array('trace' => true, 'exceptions' => true));
Then you can call any method provided by Web service:
try {
$client = new SoapClient('http://www.mysite.com/calc.wsdl',
array('trace' => true, 'exceptions' => true));
$result = $client->methodName($param1, $param2);
} catch (SoapFault $e) {
var_dump($e);
}
var_dump($result);
If some error will occur you'll catch it in try/catch block.
Upvotes: 0