How to solve xml load parsing soap payload using nusoap?

965 views Asked by At

I am new in using web service nusoap. When I try to run my program I got an error like this:

XML error parsing SOAP payload on line 1: Not well-formed (invalid token)

Here is my client.php :

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


$data = json_decode(file_get_contents("php://input"), true);

$doc_type = $data['doc_type'];
$transaction_date = $data['transaction_date'];
$file_name = $data['file_name'];
$file_path = $data['file_path'];


//create client instance
$client = new nusoap_client('http://computer_name:2224/WebService/webservice.php?wsdl' , true);

    //to check if the request method is POST or not
    if($_SERVER['REQUEST_METHOD'] == 'POST'){

        //check for error
        $err = $client->getError();

        if($err){
            //Display error
            echo '<h2>Constructor error </h2> <pre>' . $err . '</pre>' ;

        }

        //declare variables 
        $datas = array(
            'doc_type' => $doc_type,
            'transaction_date' => $transaction_date,
            'file_name'  => $file_name,
            'file_path' => $file_path
        );

        //call the function InsertData and pass the parameters being instantiated
        $result = $client->call('InsertData', $datas);

        if($client->fault){
            echo '<h2> Fault (Expect - The request contains an invalid SOAP body) </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>';
            }
        }



    } else if ($_SERVER['REQUEST_METHOD'] != 'POST'){
        echo "Method is not POST";
    }

?>

webservice.php

<?php 
   // require the nusoap.php
    require_once ('lib/nusoap.php');

    //create new instance 
    $server = new soap_server();

    //initialize WSDL support
    $server->configureWSDL('Database Data Insertion', 'urn:Insert');

    //character encoding
    $server->soap_defencoding = 'utf-8';

    // Registering different functions  of your Web service

    $server->register ('InsertData', 
        array(
            'doc_type' => 'xsd:doc_type',
            'transaction_date' =>'xsd:transaction_date',
            'file_name' =>'xsd:file_name',
            'file_path' =>'xsd:file_path'), //input values
        array('return' =>'xsd:string'),
        'urn:Insert', // Namespace
        'urn:Insertwsdl#InsertData', //SoapAction
        'rpc', //style
        'literal' // can be encoded but it doesn't work with silverlight

    );


   // function for inserting data

    function InsertData($doc_type,$transaction_date,$file_name,$file_path) {
        //set initial values for connection
        $db_host = 'localhost' ;
        $db_username = 'root' ;
        $db_password = '' ;
        $db_name = 'sample' ;

        //making connection
        $conn = new mysqli($db_host, $db_username ,$db_password , $db_name);

        //checking if connection is successful
        if($conn->connect_error){
            trigger_error('Database connection failed : ' .$conn->connect_error , E_USER_ERROR);
        }

        //inserting data in the edi_doc_type table 


            $sql = "INSERT INTO transaction_tbl (`transaction_date`,`edi_doc_type_id`,`file_name`,`file_path`,`creation_date`) 
                        VALUES ('$transaction_date',( SELECT edi_doc_type_id FROM `edi_doc_type` WHERE doc_type = $doc_type ),'$file_name','$file_path',NOW()) " ;


                //Checking query if it is successful
                if ($conn->query($sql) === false){
                    trigger_error('Wrong SQL: ' . $sql . 'Error: ' . $conn->error , E_USER_ERROR);
                }else {
                    echo "Successful ! Data is inserted in database ^__^" ;

                }
    }

    $HTTP_RAW_POST_DATA = isset ($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '' ;
    $server->service($HTTP_RAW_POST_DATA);


?>

Now , when I try to run this I got the above error. so what could be the possible problem? By the way, I can still insert in my database , but the problem is it returns the above error and not all the data in the script can be inserted . When I check my php error logs I have this :

PHP Fatal error: Wrong SQL: INSERT INTO transaction_tbl (transaction_date,edi_doc_type_id,file_name,file_path,creation_date) VALUES ('2015-05-28 22:33:00',( SELECT edi_doc_type_id FROM edi_doc_type WHERE doc_type = 997),'87749-20150528223345027_54423526_54423945.xfa','/home/sample/test/87749-20150528223345027_54423526_54423945.xfa',NOW()) Error: Subquery returns more than 1 row C:\xampp\htdocs\WebService\webservice.php on line 65

Any help will be appreciated. Thanks :)

0

There are 0 answers