dongqu9972 2015-06-25 01:53
浏览 79

如何使用nusoap解决xml加载解析soap有效负载?

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测