Hi everyone,
I wonder how is it possible to make PHP SOAP extension convert the
returned complex type to an instance of one of my classes.
Here I give you a short example:
complexTest.wsd l:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
name="complexTe st"
targetNamespace ="http://www.mydomain.co m/complexTest.wsd l"
xmlns="http://schemas.xmlsoap .org/wsdl/"
xmlns:mime="htt p://schemas.xmlsoap .org/wsdl/mime/"
xmlns:soap="htt p://schemas.xmlsoap .org/wsdl/soap/"
xmlns:tns="http ://www.mydomain.co m/complexTest.wsd l"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsd1="htt p://localhost/soapTypeTest/complexTest.xsd ">
<types>
<xsd:schema
targetNamespace ="http://localhost/soapTypeTest/complexTest.xsd "
xmlns="http://schemas.xmlsoap .org/wsdl/"
xmlns:SOAP-ENC="http://schemas.xmlsoap .org/soap/encoding/"
xmlns:soap="htt p://schemas.xmlsoap .org/wsdl/soap/"
xmlns:tns="http ://www.mydomain.co m/complexTest.wsd l"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsd1="htt p://localhost/soapTypeTest/complexTest.xsd ">
<xsd:complexTyp e name="TopicData ">
<xsd:all>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicId" type="xsd:strin g"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicType Id" type="xsd:strin g"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicName " type="xsd:strin g"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="modifiedT s" type="xsd:dateT ime"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="createdTs " type="xsd:dateT ime"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="dataType" type="xsd:strin g"/>
<xsd:element
maxOccurs="1"
minOccurs="0"
name="dataValue "
type="xsd:base6 4Binary"/>
</xsd:all>
</xsd:complexType >
</xsd:schema>
</types>
<message name="TopicData ">
<part name="TopicData " type="xsd1:Topi cData"/>
</message>
<portType name="complexTe stPortType">
<operation name="getTopic" >
<input message="tns:To picData"/>
<output message="tns:To picData"/>
</operation>
</portType>
<binding name="complexTe stBinding" type="tns:compl exTestPortType" >
<soap:binding style="rpc"
transport="http ://schemas.xmlsoap .org/soap/http"/>
<operation name="getTopic" >
<soap:operati on
soapAction="com plexTest:comple xTestPortType#g etTopic"/>
<input>
<mime:multipart Related> </mime:multipartR elated>
</input>
<output>
<soap:body
encodingStyle=" http://schemas.xmlsoap .org/soap/encoding/"
namespace="http ://www.taox.com/complexTest/binding"
use="encoded"/>
</output>
</operation>
</binding>
<service name="complexTe st">
<port binding="tns:co mplexTestBindin g" name="complexTe stPort">
<soap:address
location="http://localhost/soapTypeTest/server.php"/>
</port>
</service>
</definitions>
server.php:
<?php
ini_set('soap.w sdl_cache_enabl ed', 0);
class TopicData {
var $topicId;
var $topicTypeId;
var $topicName;
var $modifiedTs;
var $createdTs;
var $dataType;
var $dataValue;
}
class TestServer {
function getTopic($topic Data) {
$topicData->topicName = $topicData->topicId . " topic";
$topicData->createdTs = time();
return $topicData;
}
}
$server = new SoapServer("com plexTest.wsdl") ;
$server->setClass('Test Server');
$server->handle();
?>
client.php:
<?php
ini_set('soap.w sdl_cache_enabl ed', 0);
class TopicData {
var $topicId;
var $topicTypeId;
var $topicName;
var $modifiedTs;
var $createdTs;
var $dataType;
var $dataValue;
}
$topic = new TopicData;
$topic->topicId = 3;
$client = new
SoapClient("htt p://localhost/soapTypeTest/server.php?wsdl ",
array('trace' => 1));
$outObj = $client->getTopic($topi c);
var_dump($outOb j);
var_export($cli ent->__getLastReque st());
var_export($cli ent->__getLastRespo nse());
?>
What I would like to see after running client.php is that $outObj is an
instance of TopicData. Now it is a stdClass. Any ideas? (beyond that,
createdTs should be a date type, not a string)
Thank you in advance,
David
I wonder how is it possible to make PHP SOAP extension convert the
returned complex type to an instance of one of my classes.
Here I give you a short example:
complexTest.wsd l:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
name="complexTe st"
targetNamespace ="http://www.mydomain.co m/complexTest.wsd l"
xmlns="http://schemas.xmlsoap .org/wsdl/"
xmlns:mime="htt p://schemas.xmlsoap .org/wsdl/mime/"
xmlns:soap="htt p://schemas.xmlsoap .org/wsdl/soap/"
xmlns:tns="http ://www.mydomain.co m/complexTest.wsd l"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsd1="htt p://localhost/soapTypeTest/complexTest.xsd ">
<types>
<xsd:schema
targetNamespace ="http://localhost/soapTypeTest/complexTest.xsd "
xmlns="http://schemas.xmlsoap .org/wsdl/"
xmlns:SOAP-ENC="http://schemas.xmlsoap .org/soap/encoding/"
xmlns:soap="htt p://schemas.xmlsoap .org/wsdl/soap/"
xmlns:tns="http ://www.mydomain.co m/complexTest.wsd l"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsd1="htt p://localhost/soapTypeTest/complexTest.xsd ">
<xsd:complexTyp e name="TopicData ">
<xsd:all>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicId" type="xsd:strin g"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicType Id" type="xsd:strin g"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicName " type="xsd:strin g"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="modifiedT s" type="xsd:dateT ime"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="createdTs " type="xsd:dateT ime"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="dataType" type="xsd:strin g"/>
<xsd:element
maxOccurs="1"
minOccurs="0"
name="dataValue "
type="xsd:base6 4Binary"/>
</xsd:all>
</xsd:complexType >
</xsd:schema>
</types>
<message name="TopicData ">
<part name="TopicData " type="xsd1:Topi cData"/>
</message>
<portType name="complexTe stPortType">
<operation name="getTopic" >
<input message="tns:To picData"/>
<output message="tns:To picData"/>
</operation>
</portType>
<binding name="complexTe stBinding" type="tns:compl exTestPortType" >
<soap:binding style="rpc"
transport="http ://schemas.xmlsoap .org/soap/http"/>
<operation name="getTopic" >
<soap:operati on
soapAction="com plexTest:comple xTestPortType#g etTopic"/>
<input>
<mime:multipart Related> </mime:multipartR elated>
</input>
<output>
<soap:body
encodingStyle=" http://schemas.xmlsoap .org/soap/encoding/"
namespace="http ://www.taox.com/complexTest/binding"
use="encoded"/>
</output>
</operation>
</binding>
<service name="complexTe st">
<port binding="tns:co mplexTestBindin g" name="complexTe stPort">
<soap:address
location="http://localhost/soapTypeTest/server.php"/>
</port>
</service>
</definitions>
server.php:
<?php
ini_set('soap.w sdl_cache_enabl ed', 0);
class TopicData {
var $topicId;
var $topicTypeId;
var $topicName;
var $modifiedTs;
var $createdTs;
var $dataType;
var $dataValue;
}
class TestServer {
function getTopic($topic Data) {
$topicData->topicName = $topicData->topicId . " topic";
$topicData->createdTs = time();
return $topicData;
}
}
$server = new SoapServer("com plexTest.wsdl") ;
$server->setClass('Test Server');
$server->handle();
?>
client.php:
<?php
ini_set('soap.w sdl_cache_enabl ed', 0);
class TopicData {
var $topicId;
var $topicTypeId;
var $topicName;
var $modifiedTs;
var $createdTs;
var $dataType;
var $dataValue;
}
$topic = new TopicData;
$topic->topicId = 3;
$client = new
SoapClient("htt p://localhost/soapTypeTest/server.php?wsdl ",
array('trace' => 1));
$outObj = $client->getTopic($topi c);
var_dump($outOb j);
var_export($cli ent->__getLastReque st());
var_export($cli ent->__getLastRespo nse());
?>
What I would like to see after running client.php is that $outObj is an
instance of TopicData. Now it is a stdClass. Any ideas? (beyond that,
createdTs should be a date type, not a string)
Thank you in advance,
David