|
Posted by Janwillem Borleffs on 10/29/47 11:25
Piro wrote:
> I have a class that I want to make accessible to a web service. This
> class does some work in its constructor method and sets some class
> variables in its various methods. The problem I am having is creating
> an instance of this class when it is called via SOAP. I don't seem to
> have access to the constructor method or any class variables... is
> this by design? Must all methods be static? Here is my sample code:
>
A requirement to get this to work is that your soap server supports
persistency so it's able to keep track of the class instance during the
execution of the client. Persistency can be enforced with the
SoapServer->setPersistence() method.
Below is an example implementation:
Server:
<?php
class User {
public $name;
public function setName($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
session_start();
$server = new SoapServer(null, array('uri' => 'http://localhost/'));
$server->setClass('User');
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
$server->handle();
?>
Client:
<?php
$client = new SoapClient(
null,
array(
'location' => 'http://localhost/server.php',
'uri' => 'http://localhost/',
'trace' => 1
)
);
$client->setName('John');
print $client->getName();
?>
JW
Navigation:
[Reply to this message]
|