Hi all,
I've a problem with PHP5 + PEAR::SOAP.
I Have the following 2 script that implements a simple web service:
The Server Code running on WinXP + PHP5 + Apache 2.x:
----------------------------------------------------
<?php
require_once('S OAP/Server.php');
require_once('S OAP/Disco.php');
class pearsoaptest
{
var $__dispatch_map = array();
var $txt = "I am a test\n";
function __construct()
{
$this->__dispatch_m ap['AddString'] = array('in' => array('s_in' => 'string'), 'out' => array('s_out' =>
'string'), );
$this->__dispatch_m ap['GetString'] = array('in' => array(), 'out' => array('s_out' => 'string'), );
$this->txt .= "Contructor execution END\n";
}
function AddString($s_in )
{
$this->txt .= $s_in . "\n";
return $this->txt;
}
function GetString()
{
return $this->txt;
}
}
$server = new SOAP_Server();
$webservice = new pearsoaptest();
$server->addObjectMap($ webservice,'htt p://schemas.xmlsoap .org/soap/envelope/');
if (isset($_SERVER['REQUEST_METHOD ']) && $_SERVER['REQUEST_METHOD ']=='POST') {
$server->service($HTTP_ RAW_POST_DATA);
} else {
$disco = new SOAP_DISCO_Serv er($server,'pea rsoaptest');
header("Content-type: text/xml");
if (isset($_SERVER['QUERY_STRING']) && (strcasecmp($_S ERVER['QUERY_STRING'],'wsdl') == 0) ) {
echo $disco->getWSDL();
} else {
header("Content-type: text/xml");
echo $disco->getDISCO();
}
}
exit;
?>
and the client script running on WinXP + PHP5
---------------------------------------------
#!/usr/local/bin/php
<?php
require_once 'SOAP/Client.php';
try {
$_web_service_u rl = 'http://localhost/pearsoaptestser ver.php?wsdl';
$wsdl = new SOAP_WSDL($_web _service_url);
$pearsoaptest = $wsdl->getProxy();
$params = array("s_in"=>" Adding a Line 2");
$option = array();
echo "\n-- Call the web service GET methods:\n";
$ret = $pearsoaptest->GetString();
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
echo "\n-- First Call the web service ADD methods:\n";
$ret = $pearsoaptest->AddString("Add ing a Line 1");
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
echo "\n-- Call the web service ADD methods:\n";
$ret = $pearsoaptest->call("AddStrin g",$params,$opt ion);
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
echo "\n-- Call the web service GET methods:\n";
$ret = $pearsoaptest->GetString();
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage() , "\n";
}
echo "\n\n";
?>
This is the client execution output:
------------------------------------
D:\Web-Service>php pearsoaptestcli ent.php
-- Call the web service GET methods:
I am a test
Contructor execution END
-- First Call the web service ADD methods:
I am a test
Contructor execution END
Adding a Line 1
-- Call the web service ADD methods:
I am a test
Contructor execution END
Adding a Line 2
-- Call the web service GET methods:
I am a test
Contructor execution END
---------------------------------------------
As you can see the output is not the expected one:
I am a test
Contructor execution END
Adding a Line 1
Adding a Line 2
So I've the idea that the SOAP invocation of a remote class does not permit the access to the class variable to the
methods but only to the class constructor (and only the first time it was invoked).
Can someone confirm me this thesis or if is not so can someone say me where I have made errors?
Bye and thank you
Samuel Zallocco (L'Aquila - ITALY)
I've a problem with PHP5 + PEAR::SOAP.
I Have the following 2 script that implements a simple web service:
The Server Code running on WinXP + PHP5 + Apache 2.x:
----------------------------------------------------
<?php
require_once('S OAP/Server.php');
require_once('S OAP/Disco.php');
class pearsoaptest
{
var $__dispatch_map = array();
var $txt = "I am a test\n";
function __construct()
{
$this->__dispatch_m ap['AddString'] = array('in' => array('s_in' => 'string'), 'out' => array('s_out' =>
'string'), );
$this->__dispatch_m ap['GetString'] = array('in' => array(), 'out' => array('s_out' => 'string'), );
$this->txt .= "Contructor execution END\n";
}
function AddString($s_in )
{
$this->txt .= $s_in . "\n";
return $this->txt;
}
function GetString()
{
return $this->txt;
}
}
$server = new SOAP_Server();
$webservice = new pearsoaptest();
$server->addObjectMap($ webservice,'htt p://schemas.xmlsoap .org/soap/envelope/');
if (isset($_SERVER['REQUEST_METHOD ']) && $_SERVER['REQUEST_METHOD ']=='POST') {
$server->service($HTTP_ RAW_POST_DATA);
} else {
$disco = new SOAP_DISCO_Serv er($server,'pea rsoaptest');
header("Content-type: text/xml");
if (isset($_SERVER['QUERY_STRING']) && (strcasecmp($_S ERVER['QUERY_STRING'],'wsdl') == 0) ) {
echo $disco->getWSDL();
} else {
header("Content-type: text/xml");
echo $disco->getDISCO();
}
}
exit;
?>
and the client script running on WinXP + PHP5
---------------------------------------------
#!/usr/local/bin/php
<?php
require_once 'SOAP/Client.php';
try {
$_web_service_u rl = 'http://localhost/pearsoaptestser ver.php?wsdl';
$wsdl = new SOAP_WSDL($_web _service_url);
$pearsoaptest = $wsdl->getProxy();
$params = array("s_in"=>" Adding a Line 2");
$option = array();
echo "\n-- Call the web service GET methods:\n";
$ret = $pearsoaptest->GetString();
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
echo "\n-- First Call the web service ADD methods:\n";
$ret = $pearsoaptest->AddString("Add ing a Line 1");
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
echo "\n-- Call the web service ADD methods:\n";
$ret = $pearsoaptest->call("AddStrin g",$params,$opt ion);
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
echo "\n-- Call the web service GET methods:\n";
$ret = $pearsoaptest->GetString();
if (PEAR::isError( $ret))
{
print("Error: " . $ret->getMessage() . "\n");
} else {
print ($ret);
};
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage() , "\n";
}
echo "\n\n";
?>
This is the client execution output:
------------------------------------
D:\Web-Service>php pearsoaptestcli ent.php
-- Call the web service GET methods:
I am a test
Contructor execution END
-- First Call the web service ADD methods:
I am a test
Contructor execution END
Adding a Line 1
-- Call the web service ADD methods:
I am a test
Contructor execution END
Adding a Line 2
-- Call the web service GET methods:
I am a test
Contructor execution END
---------------------------------------------
As you can see the output is not the expected one:
I am a test
Contructor execution END
Adding a Line 1
Adding a Line 2
So I've the idea that the SOAP invocation of a remote class does not permit the access to the class variable to the
methods but only to the class constructor (and only the first time it was invoked).
Can someone confirm me this thesis or if is not so can someone say me where I have made errors?
Bye and thank you
Samuel Zallocco (L'Aquila - ITALY)