Return object with Zend_Soap

2019-09-01 01:50发布

问题:

I would like to return an object using Zend_Soap. I also want the object given in the WSDL file. But I can't get both to work together. It's either one or the other.

1. WSDL working, but object not returning

If in the phpdoc of my function on the soap server script, I write

 @return Application_Model_Soap_Test

I can see it in the WSDL file

<message name="getPostcodeOut">
    <part name="return" type="tns:Application_Model_Soap_Test"/>
</message>

but when I run the script, it returns an empty class:

stdClass Object
(
)

2. Get object, but wrong WSDL

If I change the server function's phpdoc info to

@return mixed Application_Model_Soap_Test

I get an object back with info:

stdClass Object
(
    [name] => Fred
    [age] => 40
)

but the WSDL file is wrong

<message name="getPostcodeOut">
    <part name="return" type="xsd:anyType"/>
</message>

Any ideas? Thanks.

回答1:

You need to pass a 'classmap' option variable in the client.

See both http://www.php.net/manual/en/soapclient.soapclient.php and http://www.php.net/manual/en/soapclient.soapclient.php about the 'classmap' option passed in the option array.

Basically it should be an array mapping your classes to the classes defined as the returned objects in the WSDL file.



回答2:

Did you try to turn off caching?

In PHP how can you clear a WSDL cache?

I had the same problem. Every request I made returned me an empty stdclass, even though the WSDL was correct. After disabling caching it worked fine for me. Give it a try.