1

I'm testing a SOAP server which must receive multiple operations in one single request. The server is configured with Symfony 2.7, PHP 7.1, and zend-soap 2.7. I can't upgrade now the versions of Symfony neither PHP except if they're the cause of this problem.

I'm trying a very dummy code. The controller follows as this:

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;
}

It basically calls a service which has one single function:

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

}

The WSDL file is this:

<?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>

And I get the next response:

<?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>

But I need this:

<?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>

Why I'm not getting both responses?

I have searched the documentation of SOAP for Symfony, PHP and Zend in order to see If I was missing some configuration option, but I can't find anything like that. I also searched unsuccessfully for this question here.

Mar
  • 45
  • 7

1 Answers1

0

Did you try to generate the WSDL using zend? Maybe your WSDL is wrong?

Try to generate it using Zend and it should work or at least you can see what you are doing wrong:

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;
}
numediaweb
  • 16,362
  • 12
  • 74
  • 110