在Nusoap中获取错误:解析SOAP有效内容时出现XML错误

时间:2017-12-27 07:10:42

标签: php xml soap

我是Soap \ NuSoap的新手 我可以连接到服务器站点但是从服务器发送数据回到客户端我无法获取数组中的数据来显示客户端站点。我必须测试以获取数据并将数据发送回其他数据库。我必须进入阵列。

显示错误

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

我不能自己修理它。请帮忙。

这是我的client.php

include("lib/nusoap.php");
$client = new nusoap_client("http://192.168.20.3/soap_server/webservice.php?wsdl");
$client->soap_defencoding = 'utf-8';
$client->encode_utf8 = false;
$client->decode_utf8 = false;
$params = array(
        'strName' => $_POST["strName"],
);
$result = $client->call("resultCustomer",$params);
$err = $client->getError();
if ($err) {
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
    exit();
}

print_r($result);

这是server.php

require_once("lib/nusoap.php");     

    //Define our namespace
    $namespace = "http://localhost/soap_server/webservice.php";
    //Create a new soap server
    $server = new soap_server();
    //Configure our WSDL
    $server->configureWSDL("getCustomer");
    $server->wsdl->schemaTargetNamespace = $namespace;
    $server->soap_defencoding = 'utf-8';
    $server->encode_utf8 = false;
    $server->decode_utf8 = false;

    //Register our method and argument parameters
    $varname = array(
               'strName' => "xsd:string"
    );

    //Add ComplexType
    $server->wsdl->addComplexType( 
        'ArrayOfString', 
        'complexType', 
        'array', 
        '', 
        '', 
           array( 
                'id_user' => array('name' => 'id_user', 'type' => 'xsd:string'), 
                'firstname'  => array('name' => 'firstname', 'type'  => 'xsd:string'),
                'username'  => array('name' => 'username', 'type'  => 'xsd:string'),
                'lastname'  => array('name' => 'lastname', 'type'  => 'xsd:string')
       ) 
    ); 
    //Add ComplexType
    $server->wsdl->addComplexType( 
        'ArrayOfString', 
        'complexType', 
        'array', 
        '', 
        'SOAP-ENC:Array', 
        array(), 
        array( 
            array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]') 
        ), 
        'tns:DataList' 
    ); 

    // Register service and method
    $server->register('resultCustomer',$varname, array('return' => 'tns:ArrayOfString'));

    function resultCustomer($strName)
    {               
            $objConnect = mysql_connect("localhost","root","") or die(mysql_error());
            $objDB = mysql_select_db("qpt-test");
            $strSQL = "SELECT * FROM qpt_user where firstname like '%".$strName."%'";
            $objQuery = mysql_query($strSQL) or die (mysql_error());
            $intNumField = mysql_num_fields($objQuery);
            $resultArray = array();
            while($obResult = mysql_fetch_array($objQuery))
            {
                $arrCol = array();
                for($i=0;$i<$intNumField;$i++)
                {
                    $arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
                }
                array_push($resultArray,$arrCol);
            }
            return $resultArray;            
    }
    $POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';

    // pass our posted data (or nothing) to the soap service
    $server->service($POST_DATA);
    exit();

0 个答案:

没有答案