0

There a Webservice on my server written in php that update a customer in an Acomba table. The service update correctly the customer but when i receive the response the webpage crash because the xml is not properly closed. I call the Webservice with ajax.

I didn't wrote either the call or the webservice but i have to fix it...

Logged error: SoapFault exception: [Client] looks like we got no XML document in C:\inetpub\wwwroot\eureka\ajax\syncContratAvenant.php:85

Stack trace: C:\inetpub\wwwroot\eureka\ajax\syncContratAvenant.php(85): SoapClient->__soapCall('saveClientAvena...', Array)

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:SOAP_AvenantAcomba" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:saveClientAvenant><param0 xsi:type="ns2:Map"><item><key xsi:type="xsd:string">noContrat</key><value xsi:type="xsd:string">FP00000000</value></item>
<item><key xsi:type="xsd:string">acombaUidClient</key><value xsi:type="xsd:string">945</value></item><item><key xsi:type="xsd:string">name</key><value xsi:type="xsd:string">Test</value></item><item><key xsi:type="xsd:string">institution</key><value xsi:type="xsd:string">000</value></item><item><key xsi:type="xsd:string">folio</key><value xsi:type="xsd:string">000000</value></item><item><key xsi:type="xsd:string">transit</key><value xsi:type="xsd:string">00000</value></item><item><key xsi:type="xsd:string">zip</key><value xsi:type="xsd:string">XXX XXX</value></item><item><key xsi:type="xsd:string">adress</key><value xsi:type="xsd:string">2 testtown</value></item><item><key xsi:type="xsd:string">phone</key><value xsi:type="xsd:string"></value></item><item><key xsi:type="xsd:string">city</key><value xsi:type="xsd:string">Test</value></item></param0></ns1:saveClientAvenant>
</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="urn:SOAP_AvenantAcomba" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body><ns1:saveClientAvenantResponse><return xsi:type="ns2:Map"><item><key xsi:type="xsd:string">reponse</key><value xsi:type="xsd:boolean">true</value></item><item><key xsi:type="xsd:string">errorMessage</key><value xsi:type="xsd:string"></value></item></return></ns1:saveClientAvenantResponse>
</SOAP-ENV:Body></SOAP-ENV:Envelop

Notice how the envelope is not properly closed there... don't know why through....

The call :

$client = new SoapClient(null, array('location' => ACOMBA_WEB_SERVICE_Avenant,
                                                 'uri'             => "urn:SOAP_AvenantAcomba",
                                                 'trace'        => 1,
                                                 'encoding'    => 'ISO-8859-1'));

            $info = array($arraySOAP => array(
                    'noContrat' => getNoContratTxt($contract->getCols('noContract')),
                    'acombaUidClient' => $contract->getCols('acombaUidClient'),
                    'name' => $contract->getCols('name') ,
                    'institution' => $contract->getCols('noInstitution'),
                    'folio' => $contract->getCols('noFolio'),
                    'transit' => $contract->getCols('noTransit'),
                    'zip' => makeSQasDQ($contract->getCols('zipAddAssurer')),
                    'adress' => makeSQasDQ(utf8_decode($contract->getCols('noAddAssurer') . ' ' . $contract->getCols('streetAddAssurer'))),
                    'phone' => '',
                    'city' => makeSQasDQ(utf8_decode($contract->getCols('townAddAssurer'))))
            );


        $resultClient = $client->__soapCall('saveClientAvenant', $info); // crash here

The service :

<?php
require_once('variables.php');

set_time_limit(900);


function saveClientAvenant($arraySOAP){

    $conn = odbc_connect(ACOMBA_DRIVER, ACOMBA_USER, base64_decode(ACOMBA_PASS));

    if (odbc_commit($conn)) {
        try {
            $nxtContrat = $arraySOAP['noContrat'];
            $nom = $arraySOAP['name'];
            $noInstitution = $arraySOAP['institution'];
            $noFolio = $arraySOAP['folio'];
            $noTransit = $arraySOAP['transit'];
            $zipCode = $arraySOAP['zip'];
            $adress = $arraySOAP['adress'];
            $phone = $arraySOAP['phone'];
            $city = $arraySOAP['city'];
            $acombaUidClient = $arraySOAP['acombaUidClient'];

            $sqlQuery = "UPDATE " . TABLE_ACOMBA_CLIENT . "
            SET
            CuSortKey = '$nom',
            CuName = '$nom',
            CuAddress = '$adress',  
            CuCity = '$city',  
            CuPostalCode = '$zipCode',
            CuPhoneNumber1 = '$phone',
            CuInstitutionNumber = '$noInstitution',
            CuBranchNumber = '$noTransit',
            CuAccountNumber = '$noFolio'
            WHERE
            CuUnique = $acombaUidClient
            ";

            if (!odbc_exec($conn, $sqlQuery)) {
                throw new Exception($sqlQuery . odbc_errormsg());
            }
        } catch (Exception $e) {
            return array('reponse' => false,
                'errorMessage' => $e->getMessage() );
        }
        odbc_close($conn);

        return array('reponse' => true,
                'errorMessage' => '' );
    }
}       



$server = new SOAPServer(null, array('uri'         => 'urn:SOAP_AvenantAcomba',
                                         'encoding'    => 'ISO-8859-1'));

$server->addFunction('saveClientAvenant');  
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
$server->handle();

?>
  • I wonder why this line is in your server script: `$HTTP_RAW_POST_DATA = file_get_contents('php://input');` Can you explain it? – Sven Oct 22 '13 at 21:30
  • check this link, it explain it better than i can : http://stackoverflow.com/questions/2731297/file-get-contentsphp-input-or-http-raw-post-data-which-one-is-better-to/2731338#2731338 –  Oct 23 '13 at 12:43
  • Thanks for replying with a link that misses the question, but made me think. `$HTTP_RAW_POST_DATA` is no superglobal, so why put data in there and then NOT use it? That variable is only populated if [always_populate_raw_data](http://de3.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data) is switched on. The answer is a mixture of convenience and evil! `SoapServer::handle()` accepts a string of data - if none is passed, `$HTTP_RAW_POST_DATA` is used instead. This line fixes the config ini setting badly: Put the contents in `$var` and pass it to `handle($var)` instead. – Sven Oct 23 '13 at 20:16

2 Answers2

0

Have you tried changing:

'encoding'    => 'ISO-8859-1'

to:

'encoding'=>'UTF-8'

? I would expect a slightly different content length with those, which is what i see as your issue.

w3c_ee
  • 11
  • 4
  • Thats too bad. If it were my project, i would try logging the output the soap-server returns before you output it. If that is chopped off, then it is a server side issue. If not, a client-side. – w3c_ee Nov 06 '13 at 21:36
0

I have experienced the same issue with invalid SOAP XML, specifically it missing </SOAP-ENV:Envelope missing its closing > when our server has been using Brotli compression to compress the XML, for some reason Brotli and Soap don't work well together.

NickMcB
  • 897
  • 1
  • 8
  • 17