Jump to content

XML error parsing SOAP payload on line 2: Invalid document end


hlabeni

Recommended Posts

I have a web service that queries an Oracle database and then returns a struct.

If there is any error on my side, I still reply the struct, except it is populated with differnt values.

If I change the coding in my error handling to return the struct populated with the error values, then it returns fine,

but if I simulate an ORACLE error (use the incorrect passoword for example) I get the following error:

"XML error parsing SOAP payload on line 2: Invalid document end"

 

Any suggestions?

Is there a way that I can display the "SOAP Payload" to see what is missing?

The following extract from my code:

 

<<<<

 

<?php

  require_once('../NuSoap/lib/nusoap.php');

  date_default_timezone_set('Africa/Johannesburg');

 

  $server = new soap_server();

  $server->configureWSDL('oracle_err', 'urn:oracle_err');

  $server->wsdl->addComplexType('ReturnRecords',

      'complexType',

      'struct',

      'all',

      '',

      array(

      'FirstVal' =>array('name'=>'FirstVal' , 'type'=>'xsd:string'),

      'SecondVal'=>array('name'=>'SecondVal', 'type'=>'xsd:string'),

      'ThirdVal' =>array('name'=>'ThirdVal' , 'type'=>'xsd:string'),

      'FourthVal'=>array('name'=>'FourthVal', 'type'=>'xsd:string'),

      'FifthVal' =>array('name'=>'FifthVal' , 'type'=>'xsd:string')));

 

  $server->wsdl->addComplexType('RecordStatus',

      'complexType',

      'struct',

      'all',

      '',

      array(

      'ErrStatus'=>array('name'=>'ErrStatus', 'type'=>'xsd:string'),   

      'FaultReason'=>array('name'=>'FaultReason', 'type'=>'xsd:string'),

      'RowsFetched'=>array('name'=>'RowsFetched', 'type'=>'xsd:decimal')));

 

  $server->wsdl->addComplexType('ReturnArray',

        'complexType',

        'array',

        'all',

        '',

        array(),

        array('RntRecs'=>array('name'=>'RntRecs','type'=>'tns:ReturnRecords[]'),

              'RecStat'=>array('name'=>'RecStat','type'=>'tns:RecordStatus')));

 

  $server->register('oracle_err',

    array('InputParam' => 'xsd:string'),

    array('return' => 'tns:ReturnArray'),

    'urn:oracle_err',

    'urn:oracle_err#oracle_err',

    'rpc',

    'encoded',

    'Testing Oracle connection.');

 

  function oracle_err($InputParam)

  {

    //The connection details to make the database connection.

    require_once('cdbCred.php');

 

    $date_stamp = date('M_d');

    $db_results = array();

    $results = array();

    $LogFile = $log_dir . "Oracle_error_" . $date_stamp . ".log";

    $record_size_limit = 64;    //To control the size of the return array.

 

    $fptr = fopen($LogFile, 'a') or die("can't open file");

 

    $sys_time = date('omd H:i:s');

 

    fwrite($fptr,"\n\n***************************************\n");

    fwrite($fptr,"* PHP - Start Time - ". $sys_time . "*\n");

    fwrite($fptr,"***************************************\n");

    fwrite($fptr,"PHP - IN WEB Service oracle_err()\n");

    fwrite($fptr,"PHP - Source code - oracle_err.php\n");

 

    //**** SETTING UP THE RETURN STRUCT variables ****

    $sys_time = date('omd H:i:s');

 

    $rows_fetched= 0;

    $fault_reason= '  ';

    $error_status = 0;

 

    $tempArray = array('FirstVal'  => "0",

                      'SecondVal' => "0",

                      'ThirdVal'  => "0",

                      'FourthVal' => "0",

                      'FifthVal'  => "0");

 

    fwrite($fptr,"PHP - RECIEVED DATA\n");

    fwrite($fptr,"PHP - InputParam =[". $InputParam ."]\n");

    fwrite($fptr,"\n") ;

 

    $conn = oci_connect($user_name, $user_pswd, $user_database);

 

    if (!$conn)

    {

      $e = oci_error();

      fwrite($fptr, "oci_error=[". $e['message'] . "]\n");

 

      $rows_fetched= 0;

      $fault_reason= "Error - CONNECTING to ORACLE database.[" . $e['message'] ."]";

      $error_status = 1;

 

      fwrite($fptr,"PHP - " . $fault_reason . "\n");

      $reply_status = array('ErrStatus'=>$error_status,

                            'FaultReason'=>$fault_reason,

                            'RowsFetched'=>$rows_fetched);

 

      $RtnArray = array('RntRecs' => $tempArray,

                      'RecStat' => $reply_status);

 

      fwrite($fptr,"PHP - LEAVING THE PHP - " . date('omd H:i:s') . "\n");

      fclose($fptr);

 

      return $RtnArray;

    }

    else

    {

      fwrite($fptr,"PHP - Connection to the ORACLE database successfull.\n");

    }

    //***********************************************************

    // LOADING the reply struct.

    //***********************************************************

    $tempArray = array('FirstVal' => "FIRST",

                        'SecondVal' => "SECOND",

                        'ThirdVal' => "THIRD",

                        'FourthVal' => "FOURTH",

                        'FifthVal' => "FIFTH");

 

    array_push($results,$tempArray);

 

    $tempArray = array('FirstVal' => "ONE",

                        'SecondVal' => "TWO",

                        'ThirdVal' => "THREE",

                        'FourthVal' => "FOUR",

                        'FifthVal' => "FIVE");

 

    array_push($results,$tempArray);

 

    $reply_status = array('ErrStatus'=>$error_status,

                          'FaultReason'=>$fault_reason,

                          'RowsFetched'=>count($results));

 

    $RtnArray = array('RntRecs' => $results,

                    'RecStat' => $reply_status);

 

    fwrite($fptr,"\n");

    fwrite($fptr,"PHP - DISCONNECTING from ORACLE.\n\n");

    oci_close($conn);

 

    fwrite($fptr,"PHP - LEAVING THE PHP - " . date('omd H:i:s') . "\n");

    fclose($fptr);

 

    return $RtnArray;

  }

  $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';

  $server->service($HTTP_RAW_POST_DATA);

?>

 

AND the call to the web service:

 

<?php

  // Pull in the NuSOAP code

  require_once('../lib/nusoap.php');

  date_default_timezone_set('Africa/Johannesburg');

 

  $client = new nusoap_client('http://myserver/web/services/oracle_err?wsdl');

  echo 'ORACLE ERROR simulation... <br>';

 

  $input_parameter = "1";

 

  $result = $client->call('oracle_err', array('InputParam'=>$input_parameter));

 

  echo 'Back at the client<br>';

  echo 'Result=['. $result .'] <br>';

  echo 'Count of Result='. count($result) . '<br>';

  if ($client->fault)

  {

    echo '<h2>Fault</h2><pre>';

    print_r($result);

    echo '</pre>';

  }

  else

  {

    $err = $client->getError();

    if ($err)

    {

        echo '<h2>Error</h2><pre>' . $err . '</pre>';

    }

    else

    {

        echo '<h2>Result</h2><pre>';

        print_r($result);

      echo '</pre>';

    }

  }

  echo 'END';

?>

  • 2 weeks later...

After scratching around I found a really good web site www.nyphp.org/PHundamentals where they described some of the error handling basics. I found in the php.ini file I had set display_errors = "On" and by changing that to “Off” solved the problem.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.