php - Passing Objects to Zend Soap Server -



php - Passing Objects to Zend Soap Server -

i'm trying implement soap server , i'm trying see if soap server in zend framework (1) need. interested in trying take advantage of it's auto-discovery create wsdl don't have maintain 1 separately time changes made functions or info types.

i set basic server , able auto-discovery seemingly want, , played class map in client , able populate model returned info couple of complex info types. however, can't seem figure out how pass client object , have show on far end.

when passed in array of values (nested/associated), client produced desired result in 'output' types/models/objects. when i'm trying pass object client code, shows on server array of values (and not associative 1 - keys dropped. on 1 other test, tried nesting objects, sec object showed stdclass @ to the lowest degree had expected key/values, outer 1 sequential array)

it appears autodiscover @ to the lowest degree pretending it's ready want, don't know how info object sent client show @ server.

data received server code:

array ( 0 => 4, 1 => 12, 2 => 7, 3 => 98.6, 4 => 9.18, 5 => 3.1415, 6 => 'foobar', 7 => 'change', 8 => 'bumblebee', )

input class:

class inputtype { /** * @var integer $intone */ public $intone; /** * @var integer $inttwo */ public $inttwo; /** * @var integer $intthree */ public $intthree; /** * @var float $floatone */ public $floatone; /** * @var float $floattwo */ public $floattwo; /** * @var float $floatthree */ public $floatthree; /** * @var string $stringone */ public $stringone; /** * @var string $stringone */ public $stringtwo; /** * @var string $stringthree */ public $stringthree; }

sample complex object (output parent layer)

require_once('soap/types/testclasstype.php'); class testtype { /** * @var integer $intvar */ public $intvar; /** * @var float $floatvar */ public $floatvar; /** * @var string $stringvar */ public $stringvar; /** * @var array $arrayvar */ public $arrayvar; /** * @var testclasstype $classvar */ public $classvar; public function __construct() { $this->classvar = new testclasstype(); } }

test class model (child of output)

class testclasstype { /** * @var integer $testint */ public $testint; /** * @var float $testfloat */ public $testfloat; /** * @var string $teststring */ public $teststring; }

server code (functions):

require_once('soap/types/inputtype.php'); require_once('soap/types/testtype.php'); require_once('soap/types/testclasstype.php'); class soap_server { /** * complex type * * @param inputtype $inp * @return testtype */ public function get_test_type($inp) { error_log("input: " . var_export($inp,1)); $tt = new testtype(); $tt->intvar = $inp->intone; $tt->floatvar = $inp->floatone; $tt->stringvar = $inp->stringone; $tt->arrayvar = array( 'int' => $inp->intthree, 'float' => $inp->floatthree, 'string' => $inp->stringthree ); $tt->classvar->testint = $inp->inttwo; $tt->classvar->testfloat = $inp->floattwo; $tt->classvar->teststring = $inp->stringtwo; homecoming $tt; } }

server request handler (run on apache2):

require_once('soap/types/inputtype.php'); require_once('soap/types/testtype.php'); require_once('soap/types/testclasstype.php'); require_once('soap/server.php'); if(isset($_get['wsdl'])) { //return wsdl handlewsdl(); } else { //handle soap request handlesoap(); } exit(); function handlewsdl() { require_once('zend/soap/autodiscover.php'); $autodiscover = new zend_soap_autodiscover(); $autodiscover->setclass('soap_server'); ob_clean(); ob_start(); $autodiscover->handle(); } function handlesoap() { $wsdl = "http://localhost/soap/zendserver.php?wsdl"; require_once('zend/soap/server.php'); $server = new zend_soap_server($wsdl); $server->setclass('soap_server'); $server->setclassmap( array( 'inputtype' => 'inputtype', 'testtype' => 'testtype', 'testclasstype' => 'testclasstype' ) ); $server->handle(); }

testing client code:

require_once('soap/types/inputtype.php'); require_once('soap/types/testtype.php'); require_once('soap/types/testclasstype.php'); require_once('zend/soap/client.php'); $wsdl = "http://localhost/soap/zendserver.php?wsdl"; $client = new zend_soap_client($wsdl, array('cache_wsdl' => false )); $client->setclassmap( array( 'inputtype' => 'inputtype', 'testtype' => 'testtype', 'testclasstype' => 'testclasstype' ) ); $client->setwsdlcache(false); $bar = new inputtype(); $bar->intone = 4; $bar->floatone = 98.6; $bar->stringone = "foobar"; $bar->inttwo = 12; $bar->floattwo = 9.18; $bar->stringtwo = "change"; $bar->intthree = 7; $bar->floatthree = 3.1415; $bar->stringthree = "bumblebee"; $result = $client->get_test_type($bar);

autodiscover wsdl:

<?xml version="1.0" encoding="utf-8"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/soap/zendserver.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="soap_server" targetnamespace="http://localhost/soap/zendserver.php"> <types> <xsd:schema targetnamespace="http://localhost/soap/zendserver.php"> <xsd:complextype name="inputtype"> <xsd:all> <xsd:element name="intone" type="xsd:int" nillable="true"/> <xsd:element name="inttwo" type="xsd:int" nillable="true"/> <xsd:element name="intthree" type="xsd:int" nillable="true"/> <xsd:element name="floatone" type="xsd:float" nillable="true"/> <xsd:element name="floattwo" type="xsd:float" nillable="true"/> <xsd:element name="floatthree" type="xsd:float" nillable="true"/> <xsd:element name="stringone" type="xsd:string" nillable="true"/> <xsd:element name="stringtwo" type="xsd:string" nillable="true"/> <xsd:element name="stringthree" type="xsd:string" nillable="true"/> </xsd:all> </xsd:complextype> <xsd:complextype name="testclasstype"> <xsd:all> <xsd:element name="testint" type="xsd:int" nillable="true"/> <xsd:element name="testfloat" type="xsd:float" nillable="true"/> <xsd:element name="teststring" type="xsd:string" nillable="true"/> </xsd:all> </xsd:complextype> <xsd:complextype name="testtype"> <xsd:all> <xsd:element name="intvar" type="xsd:int" nillable="true"/> <xsd:element name="floatvar" type="xsd:float" nillable="true"/> <xsd:element name="stringvar" type="xsd:string" nillable="true"/> <xsd:element name="arrayvar" type="soap-enc:array" nillable="true"/> <xsd:element name="classvar" type="tns:testclasstype" nillable="true"/> </xsd:all> </xsd:complextype> </xsd:schema> </types> <porttype name="soap_serverport"> <operation name="get_test_type"> <documentation>get complex type</documentation> <input message="tns:get_test_typein"/> <output message="tns:get_test_typeout"/> </operation> </porttype> <binding name="soap_serverbinding" type="tns:soap_serverport"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="get_test_type"> <soap:operation soapaction="http://localhost/soap/zendserver.php#get_test_type"/> <input> <soap:body use="encoded" encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.localhost.com/soap/zendserver.php"/> </input> <output> <soap:body use="encoded" encodingstyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/soap/zendserver.php"/> </output> </operation> </binding> <service name="soap_serverservice"> <port name="soap_serverport" binding="tns:soap_serverbinding"> <soap:address location="http://localhost/soap/zendserver.php"/> </port> </service> <message name="get_test_typein"> <part name="inp" type="tns:inputtype"/> </message> <message name="get_test_typeout"> <part name="return" type="tns:testtype"/> </message> </definitions>

php zend-framework soap

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -