Клиент SOAP получает пустой стандартный класс

Я не понимаю, почему я получаю пустой объект stdclass.

Вот код:

$client = new Zend_Soap_Client('http://urltocodethatgenerateswsdl?wsdl', $options);
$result = $client->sayHello(array( 'who' => 'Heidi'));
Zend_Debug::dump($client->getLastResponse());
Zend_Debug::dump($result);

Вот что я получаю для lastResponse:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://urltocodethatgenerateswsdl">
    <SOAP-ENV:Body>
        <ns1:sayHelloResponse>
            <return>Say Hello Heidi</return>
        </ns1:sayHelloResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

А вот дамп $result

object(stdClass)#23 (0) {}

Это почему? Кто-нибудь может объяснить?

ОБНОВЛЕНИЕ: добавлен WSDL (автоматически созданный Zend с помощью AutoDiscovery)

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://clxpreview.ch/index/soap" 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="Service_Soap" targetNamespace="http://clxpreview.ch/index/soap">
<types>
    <xsd:schema targetNamespace="http://urltocodethatgenerateswsdl">
        <xsd:complexType name="User">
            <xsd:all>
                <xsd:element name="username" type="xsd:string" nillable="true"/>
                <xsd:element name="password" type="xsd:string" nillable="true"/>
            </xsd:all>
        </xsd:complexType>
    </xsd:schema>
</types>
<portType name="Service_SoapPort">
    <operation name="getSystemTime">
        <documentation>getSystemTime</documentation>
        <input message="tns:getSystemTimeIn"/>
        <output message="tns:getSystemTimeOut"/>
    </operation>
    <operation name="sayHello">
        <documentation>sayHello</documentation>
        <input message="tns:sayHelloIn"/>
        <output message="tns:sayHelloOut"/>
    </operation>
    <operation name="getUser">
        <documentation>setUser</documentation>
        <input message="tns:getUserIn"/>
        <output message="tns:getUserOut"/>
    </operation>
    <operation name="setUser">
        <documentation>setUser</documentation>
        <input message="tns:setUserIn"/>
        <output message="tns:setUserOut"/>
    </operation>
</portType>
<binding name="Service_SoapBinding" type="tns:Service_SoapPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getSystemTime">
        <soap:operation soapAction="http://urltocodethatgenerateswsdl#getSystemTime"/>
        <input>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </input>
        <output>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </output>
    </operation>
    <operation name="sayHello">
        <soap:operation soapAction="http://urltocodethatgenerateswsdl#sayHello"/>
        <input>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </input>
        <output>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </output>
    </operation>
    <operation name="getUser">
        <soap:operation soapAction="http://urltocodethatgenerateswsdl#getUser"/>
        <input>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </input>
        <output>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </output>
    </operation>
    <operation name="setUser">
        <soap:operation soapAction="http://urltocodethatgenerateswsdl#setUser"/>
        <input>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </input>
        <output>
            <soap:body use="literal" namespace="http://urltocodethatgenerateswsdl"/>
        </output>
    </operation>
</binding>
<service name="Service_SoapService">
    <port name="Service_SoapPort" binding="tns:Service_SoapBinding">
        <soap:address location="http://urltocodethatgenerateswsdl"/>
    </port>
</service>
<message name="getSystemTimeIn"/>
<message name="getSystemTimeOut">
    <part name="return" type="xsd:string"/>
</message>
<message name="sayHelloIn">
    <part name="who" type="xsd:string"/>
</message>
<message name="sayHelloOut">
    <part name="return" type="xsd:string"/>
</message>
<message name="getUserIn">
    <part name="uid" type="xsd:int"/>
</message>
<message name="getUserOut">
    <part name="return" type="tns:User"/>
</message>
<message name="setUserIn">
    <part name="user" type="tns:User"/>
</message>
<message name="setUserOut">
    <part name="return" type="xsd:string"/>
</message>
</definitions>

заранее спасибо

Кельвин


person Kel    schedule 04.05.2012    source источник
comment
Работает ли сервис с родным SoapClient? Опубликуйте WSDL, это может быть проблемой. Служба может возвращать правильные данные, но если WSDL неисправен, клиент мыла может не найти его.   -  person MrCode    schedule 04.05.2012


Ответы (2)


Я нашел причину, почему он не работал. Мне пришлось отключить кеширование в конфиге и добавить опцию не кешировать в сделанный мной запрос.

Либо отключите кеширование с помощью ini_set, либо внеся изменения в ваш php.ini:

ini_set("soap.wsdl_cache_enabled", 0);

Я также добавил в свой запрос следующий параметр option:

array('cache_wsdl' => WSDL_CACHE_NONE)

Вот статья, которую я нашел в Stackoverflow: Как в PHP можно очистить кэш WSDL?

person Kel    schedule 14.06.2012

Похоже, в этом посте обсуждалась та же проблема:

Вернуть объект с помощью Zend_Soap

Цитата:

Вам необходимо передать переменную параметра classmap в клиенте. См. оба http://www.php.net/manual/en/soapclient.soapclient.php и http://www.php.net/manual/en/soapclient.soapclient.php о параметре classmap, переданном в массиве параметров. По сути, это должен быть массив, сопоставляющий ваши классы с классами, определенными как возвращенные объекты в файле WSDL.

Люциан

person Lucian Depold    schedule 15.05.2012
comment
Спасибо за ваш пост. Я использовал карту классов. Проблема была связана с кэшированием WSDL. - person Kel; 14.06.2012