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.wsdl:
<?xml version="1.0" encoding="UTF-8"?>
<definitions
name="complexTest"
targetNamespace="http://www.mydomain.com/complexTest.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.mydomain.com/complexTest.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsd1="http://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="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.mydomain.com/complexTest.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsd1="http://localhost/soapTypeTest/complexTest.xsd">
<xsd:complexType name="TopicData">
<xsd:all>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicId" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicTypeId" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="topicName" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="modifiedTs" type="xsd:dateTime"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="createdTs" type="xsd:dateTime"/>
<xsd:element maxOccurs="1" minOccurs="0"
name="dataType" type="xsd:string"/>
<xsd:element
maxOccurs="1"
minOccurs="0"
name="dataValue"
type="xsd:base64Binary"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="TopicData">
<part name="TopicData" type="xsd1:TopicData"/>
</message>
<portType name="complexTestPortType">
<operation name="getTopic">
<input message="tns:TopicData"/>
<output message="tns:TopicData"/>
</operation>
</portType>
<binding name="complexTestBinding" type="tns:complexTestPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getTopic">
<soap:operation
soapAction="complexTest:complexTestPortType#getTop ic"/>
<input>
<mime:multipartRelated> </mime:multipartRelated>
</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="complexTest">
<port binding="tns:complexTestBinding" name="complexTestPort">
<soap:address
location="http://localhost/soapTypeTest/server.php"/>
</port>
</service>
</definitions>
server.php:
<?php
ini_set('soap.wsdl_cache_enabled', 0);
class TopicData {
var $topicId;
var $topicTypeId;
var $topicName;
var $modifiedTs;
var $createdTs;
var $dataType;
var $dataValue;
}
class TestServer {
function getTopic($topicData) {
$topicData->topicName = $topicData->topicId . " topic";
$topicData->createdTs = time();
return $topicData;
}
}
$server = new SoapServer("complexTest.wsdl");
$server->setClass('TestServer');
$server->handle();
?>
client.php:
<?php
ini_set('soap.wsdl_cache_enabled', 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("http://localhost/soapTypeTest/server.php?wsdl",
array('trace' => 1));
$outObj = $client->getTopic($topic);
var_dump($outObj);
var_export($client->__getLastRequest());
var_export($client->__getLastResponse());
?>
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