Обработка нескольких операций на сервере SOAP с помощью Zend

Я тестирую сервер SOAP, который должен получать несколько операций в одном запросе. Сервер настроен на Symfony 2.7, PHP 7.1 и zend-soap 2.7. Я не могу сейчас обновить ни версии Symfony, ни PHP, за исключением случаев, когда они являются причиной этой проблемы.

Я пробую очень фиктивный код. Контроллер выглядит следующим образом:

if ($request->isMethod('GET') and isset($_GET['wsdl'])) {
    $response = new Response();
    $response->headers->set('Content-Type', 'text/xml');

    $wsdl = fopen('dummy.wsdl', 'r');

    $response->setContent(fread($wsdl, filesize('dummy.wsdl')));

    return $response;
}
elseif ($request->isMethod('POST')) {
    $server = new Server('dummy.wsdl');
    $server->setObject($this->get('app.service.soap_dummy'));

    $response = new Response();
    $response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1');

    ob_start();
    $server->handle();
    $response->setContent(ob_get_clean());

    return $response;
}

В основном он вызывает службу, которая имеет одну единственную функцию:

class SoapDummy
{
/**
 * @return int
 */
public function getNumber()
{
    return 1;
}

}

WSDL-файл таков:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/soap/dummy" 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:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" name="SoapDummy" targetNamespace="http://localhost/soap/dummy">
<types>
    <xsd:schema targetNamespace="http://localhost/soap/dummy"/>
</types>
<portType name="SoapDummyPort">
    <operation name="getNumber">
        <documentation>getNumber</documentation>
        <input message="tns:getNumberIn"/>
        <output message="tns:getNumberOut"/>
    </operation>
</portType>
<binding name="SoapDummyBinding" type="tns:SoapDummyPort">
    <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="getNumber">
        <soap:operation soapAction="http://localhost/soap/dummy#getNumber"/>
        <input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/soap/dummy"/></input>
        <output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/soap/dummy"/></output>
    </operation>
</binding>
<service name="SoapDummyService">
    <port name="SoapDummyPort" binding="tns:SoapDummyBinding">
        <soap:address location="http://localhost/soap/dummy"/>
    </port>
</service>
<message name="getNumberIn"/>
<message name="getNumberOut">
    <part name="return" type="xsd:int"/>
</message>

I do the next request:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Body>
    <getNumber xmlns="http://localhost/soap/producto"/>
    <getNumber xmlns="http://localhost/soap/producto"/>
</Body>
</Envelope>

И получаю следующий ответ:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/soap/dummy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:getNumberResponse>
            <return xsi:type="xsd:int">1</return>
        </ns1:getNumberResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Но мне нужно это:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/soap/dummy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:getNumberResponse>
            <return xsi:type="xsd:int">1</return>
        </ns1:getNumberResponse>
        <ns2:getNumberResponse>
            <return xsi:type="xsd:int">1</return>
        </ns2:getNumberResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Почему я не получаю оба ответа?

Я просмотрел документацию SOAP для Symfony, PHP и Zend, чтобы увидеть, не пропустил ли я какой-либо параметр конфигурации, но я не могу найти ничего подобного. Я также безуспешно искал этот вопрос здесь.


person Mar    schedule 10.12.2018    source источник


Ответы (1)


Вы пытались сгенерировать WSDL с помощью Zend? Может быть, ваш WSDL неверен?

Попробуйте сгенерировать его с помощью Zend, и он должен работать, или, по крайней мере, вы сможете увидеть, что вы делаете неправильно:

use Symfony\Component\HttpFoundation\Response;
use Zend\Soap\AutoDiscover;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
....

/**
 * Generate a WSDL for the soap client.
 *
 * @Route("/soap/{client}", name="gateway_wsdl", defaults={"client"="default"}, requirements={
 *     "client"="default|some-client-id"
 * })
 * @param string $client
 * @return Response
 */
public function wsdlAction(string $client): ?Response
{
    $url = $this->generateUrl('gateway_server', ['client' => $client], UrlGeneratorInterface::ABSOLUTE_URL);

    // set up WSDL auto‑discovery
    $wsdl = new AutoDiscover();

    // attach SOAP service class
    $wsdl->setClass(SoapDummy::class);

    // set SOAP action URI
    $wsdl->setUri($url);

    // Generate a response
    $response = new Response();
    $response->headers->set('Content-Type', 'text/xml; charset=utf-8');
    $response->setContent($wsdl->toXml());

    return $response;
}
person numediaweb    schedule 05.12.2019