简体   繁体   中英

Problem in PHP and SOAP-Client Call method two parameters and one ArrayMultidimensional

I have problem with the call to a method of a WebServer that requires three parameters of type String and another that is a sub-element that has another three parameters. I pass everything as a multidimensional array but it does not work. In the structure sent to the webserver by SOAPClient, it does not add the multi-destination array, it only keeps the first two parameters.

CODE PHP EXAMPLE SOAP:


$ws = new \SoapClient($this->getWSUrl()
                ,[
                'trace'=>true,
                'soap_version'=>SOAP_1_2,
                'encoding'=>'utf-8',
                'connection_timeout'=>'10',
                'cache_wsdl'=> WSDL_CACHE_NONE,
                ]);

$parameters = array(
    'token' => 'xxxxxx',
    'usuario' => 'xxxxxxx',
    'archivo' => array(
        'fileType' => 'text/xml​',
        'nombre' => 'test.xml',
        'xml' => 'PD94bW..xxxxxxxxxx.0dWQ+'
    )
);

$ws->MyFunctionInWebServer($parameters);

echo $ws->__getLastRequest();

The XML generated by SOAP is the following and it is wrong because it does not have the element "archivo"

OUT Request SOAP:


<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://xxxxxxxxxxx.xxx/">
 <env:Body>
  <ns1:enviarSolicitud>
   <token>xxxxxxxx</token>
   <usuario>xxxxxx</usuario>
  </ns1:enviarSolicitud>
 </env:Body>
</env:Envelope>

When the Request would have to be:


<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://xxxxxxxxxxx.xxx/">
 <env:Body>
  <ns1:enviarSolicitud>
   <token>xxxxxxxx</token>
   <usuario>xxxxxx</usuario>
   <archivo>
     <fileType>text/xml​</fileType>
     <nombre>test_21.xml</nombre>
     <xml>PD94xxxxxx0dWQ+</xml>
   </archivo>
  </ns1:enviarSolicitud>
 </env:Body>
</env:Envelope>

You can pass that type by SOAPClient..???

My Solution is use SoapVar() in $parametersArray and is valid for string XML BaseEncode64 :

$ws = new \SoapClient($this->getWSUrl()
                , [
                    //'trace' => true,
                    'encoding' => 'utf-8',
                    'connection_timeout' => '10',
                    'cache_wsdl' => WSDL_CACHE_MEMORY,
                ]);

            $parm = array();
            $subparm = array();

            $parm[] = new SoapVar($parametersArray['token'], XSD_STRING, null, null, 'token');
            $parm[] = new SoapVar($parametersArray['usuario'], XSD_STRING, null, null, 'usuario');
            $subparm[] = new SoapVar($parametersArray['archivo']['fileType'], XSD_STRING, null, null, 'fileType');
            $subparm[] = new SoapVar($parametersArray['archivo']['nombre'], XSD_STRING, null, null, 'nombre');
            $subparm[] = new SoapVar($parametersArray['archivo']['xml'], XSD_STRING, null, null, 'xml');
            $parm[] = new SoapVar($subparm, SOAP_ENC_OBJECT, null, null, 'archivo');
            $resp = new SoapVar($parm, SOAP_ENC_OBJECT);

            $data = json_decode(json_encode($ws->generarSolicitud($resp)->return), true);

            //exit(debug($ws->__getLastRequest()));

Alternative easy, is not valid for my dataArray in 'xml', change stringBaseCode64 ;-(

$ws = new \SoapClient($this->getWSUrl()
                , [
                    //'trace' => true,
                    'encoding' => 'utf-8',
                    'connection_timeout' => '10',
                    'cache_wsdl' => WSDL_CACHE_MEMORY,
                ]);

$data = json_decode(json_encode($ws->generarSolicitud($parametersArray)->return), true);

//exit(debug($ws->__getLastRequest()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM