Re: [SOAP] Re: Passing objects to soap server, complexType, classmap
| From: | Michael Rasmussen | Date: | Tue, 20 Jun 2006 09:38:30 +0000 |
| Subject: | Re: [SOAP] Re: Passing objects to soap server, complexType, classmap | ||
| References: | 1 2 3 4 5 | Groups: | php.soap |
| Request: | Send a blank email to php-soap+get-2322@lists.php.net to get a copy of this message | ||
On Tue, 20 Jun 2006 11:26:03 +1200, Morgan Pyne wrote:
>
> However, it was my understanding that this was the purpose of using
> classmaps with the soap extension i.e. mapping (on both ends of a SOAP
> connection) from WSDL complexTypes to PHP classes.
>
> If this is not what classmaps are supposed to be used for, can you explain
> to me how they should work and when they should be used?
>
I have never used the classmap option before but inspired by this thread
I made a small test. It shows, indeed, that ext/SOAP does solve your
problem:-)
WSDL
<?php
class person {
public $firstname;
public $lastname;
}
class client {
private $link;
public function __construct($wsdl)
{
$this->link = new SoapClient(
$wsdl, array(
'classmap' => array('input', 'person'),
'trace' => true
));
}
public function newPerson(person $p)
{
try {
$this->link->newPerson($p);
}
catch (SoapFault $sf)
{
print_r ($sf->getMessage());
$this->debug();
}
}
public function debug()
{
echo $this->link->__getLastRequest(), "\n";
echo $this->link->__getLastResponse(), "\n";
}
}
$client = new client('test.wsdl');
$person = new person();
$person->firstname = 'Donald';
$person->lastname = 'Duck';
$client->newPerson($person);
?>
Server
<?php
class testInput {
private $firstname;
private $lastname;
public function getPerson()
{
return $this->firstname . " " . $this->lastname;
}
}
class server {
public function newPerson(testInput $p)
{
return new SoapFault('client', $p->getPerson());
}
}
ini_set('soap.wsdl_cache_enabled', '0');
$s = new SoapServer(
'test.wsdl',
array('classmap' => array('input' => 'testInput'))
);
$s->setClass('server');
$s->handle();
?>
Client
<?php
class person {
public $firstname;
public $lastname;
}
class client {
private $link;
public function __construct($wsdl)
{
$this->link = new SoapClient(
$wsdl, array(
'classmap' => array('input', 'person'),
'trace' => true
));
}
public function newPerson(person $p)
{
try {
$this->link->newPerson($p);
}
catch (SoapFault $sf)
{
print_r ($sf->getMessage());
$this->debug();
}
}
public function debug()
{
echo $this->link->__getLastRequest(), "\n";
echo $this->link->__getLastResponse(), "\n";
}
}
$client = new client('test.wsdl');
$person = new person();
$person->firstname = 'Donald';
$person->lastname = 'Duck';
$client->newPerson($person);
?>
--
Hilsen/Regards
Michael Rasmussen
http://keyserver.veridis.com:11371/pks/lookup?op=get&search=0xE3E80917