Zend Soap server returned a String

1

Raise a SOAP server using Zend Framework and SlimFramework Soap, the call to wsdl works correctly and the result is in xML but when I call a function, it returns the XML as a string

My Code:


    use Zend\Soap\AutoDiscover;
    use Zend\Soap\Server as SoapServer;


    // MySoapServer class used defined web service method
    // Remark : "Zend\Soap\AutoDiscover" use function description , @param and @return to generate WSDL. 
    class MySoapServer {
        public $app;
        private $user_id = '';
        private $agencia_id = '';
        private $user_auth = false;

        public function __construct() {
            global $app;
            $this->app = $app;
        }

        private function array_to_xml( $data, &$xml_data ) {
            foreach( $data as $key => $value ) {
                if( is_numeric($key) ){
                    $key = 'item'.$key;
                }
                if( is_array($value) ) {
                    $subnode = $xml_data->addChild($key);
                    $this->array_to_xml($value, $subnode);
                } else {
                    $xml_data->addChild("$key",htmlspecialchars("$value"));
                }
             }
        }

        /**
         * processRequest Funcion que proporciona informacion del cliente, detalle de los pagos pendientes del mismo.
         *
         * @param string $inputParam1
         * @param float  $tipoTrx
         * @param string  $nroDocumento
         * @param string  $moneda
         * @return string $response
         */
        public function processRequest($codServicio, $tipoTrx, $nroDocumento, $moneda){
            $xml = new SimpleXMLElement('');
            $returl_array = [];


            $returl_array = array(
                'cabecera' => [
                    'codRetorno' => '000',
                    'desRetorno' => 'Aprobado',
                    'nombreApellido' => 'Juan Jose Leon',
                    'cantFilas' => 25
                ]
            );

            $this->array_to_xml($returl_array, $xml);
            return $xml->asXML();
        }
    }

    //GROUP FOR ACCOUN, LOGIN VERSION
    $app->group('/api', function () use ($app) {
        $app->get("/wsdl",function() use ($app){
            $autodiscover = new AutoDiscover();
            $autodiscover   ->setClass('MySoapServer')
                            ->setServiceName('processRequest')
                            ->setUri(WEBSERVICE_URL);

            $response = $app->response();
            $response->header('Content-type', 'Content-type: application/xml');
            echo $autodiscover->toXml();
        });

        $app->post("/",function() use ($app){
            $response = $app->response();
            $response->header('Content-type', 'Content-type: application/xml');

            $options = array('uri' =>WEBSERVICE_URL,'location' => WEBSERVICE_URL);

            $server = new SoapServer(WEBSERVICE_URL."/wsdl", $options);

            $server->setClass("MySoapServer");
            $server->handle();
        });
    });

Result:

    
asked by Osias Arnoldo Blanco 18.10.2018 в 16:19
source

0 answers