Handling SOAP answers
| From: | Klaasjan Tukker | Date: | Sun, 29 Dec 2002 20:50:37 +0000 |
| Subject: | Handling SOAP answers | ||
| Groups: | php.pear.dev php.soap | ||
| Request: | Send a blank email to pear-dev+get-11929@lists.php.net to get a copy of this message | ||
Given a server and client (code below):
How do I convert the answer of the "echoStruct" (input is a SoapStruct-Object), back into
an SoapStruct? The current response is an "stdClass" object.
With kind regards,
Klaasjan Tukker
SERVER:
<?php
require_once 'SOAP/Server.php';
$server = new SOAP_Server;
class SOAP_Example_Server {
var $__dispatch_map = array();
function SOAP_Interop_GroupB() {
$this->__dispatch_map['echoStructAsSimpleTypes'] =
array('in' => array('inputStruct' => 'SOAPStruct'),
'out' => array(
'outputString' => 'string',
'outputInteger' => 'int',
'outputFloat' => 'float')
);
$this->__dispatch_map['echoStruct'] =
array('in' => array('inputStruct' => 'SOAPStruct'),
'out' => array('outputStruct' => 'SOAPStruct')
);
}
function &echoStruct(&$struct) {
return $struct;
}
function &echoStructAsSimpleTypes (&$struct)
{
# convert a SOAPStruct to an array
return array(
new SOAP_Value('outputString','string',$struct->varString),
new SOAP_Value('outputInteger','int',$struct->varInt),
new SOAP_Value('outputFloat','float',$struct->varFloat)
);
}
}
$soapclass = new SOAP_Example_Server();
$server->addObjectMap($soapclass,'urn:SOAP_Example_Server');
$server->service($HTTP_RAW_POST_DATA);
?>
CLIENT:
<?
include("SOAP/Client.php");
$client = new Soap_Client('http://localhost/sample/server2.php');
class SOAPStruct {
var $varString;
var $varInt;
var $varFloat;
function SOAPStruct($s=NULL, $i=NULL, $f=NULL) {
$this->varString = $s;
$this->varInt = $i;
$this->varFloat = $f;
}
}
$struct = new SOAPStruct('test string',123,123.123);
$options = array('namespace' => 'urn:SOAP_Example_Server',
'trace' => 1);
$result = $client->call("echoStruct",$struct,$options);
echo "CLASS: ".get_class($result)."\n";
?>