You are here: Re: SOAP question - creating instances/ accessing constructor method? « PHP Programming Language « IT news, forums, messages
Re: SOAP question - creating instances/ accessing constructor method?

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация