0

我正在尝试使用 PHP 和 nuSoap 创建一个 Web 服务,但每次尝试执行它时都会出现错误:

第 1 行解析 SOAP 有效负载的 XML 错误:格式不正确(无效令牌)

任何人都可以看到有什么问题吗?

服务.php

<?php
require 'lib/nusoap.php';

$server = new nusoap_server();
$server->configureWSDL("casamitger" . "urn:casamitger");
$server->wsdl->schemaTargetNamespace = 'urn:casamitger';
include 'functions.php';

//getAvailabilities
$server->wsdl->addComplexType('Availabilities','complexType','struct','all','',array(
   'StartDate' => array('name' => 'StartDate', 'type' => 'xsd:date'), 
   'EndDate' => array('name' => 'EndDate', 'type' => 'xsd:date'),
   'State' => array('name' => 'State', 'type' => 'xsd:string'), 
));

$server->wsdl->addComplexType('ArrayOfAvailabilities', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
    array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Availabilities[]')), 'tns:Availabilities');


$server->register(
    'getAvailabilities',
    array(
        "SessionID"       => 'xsd:string', 
        "AccommodationId" => 'xsd:integer'
    ),
    array("return" => 'tns:ArrayOfAvailabilities')
);

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

函数.php

function getAvailabilities($sessionID, $accommodation_code) {
    $connection = mysqli_connect("localhost", "root", "", "casamitger");
    if (authenticate($sessionID)) {
        $user = getUser($sessionID);
        $query = mysqli_query($connection, "SELECT count(AccommodationId) c FROM UserAccommodations WHERE AccommodationId = '$accommodation_code' AND CompanyId = '$user'") or die();
        $row = mysqli_fetch_object($query);
        $count = $row->c;
        if ($count > 0) {
            $query = mysqli_query($connection, "SELECT StartDate,EndDate,State FROM Availabilities WHERE AccommodationId = '$accommodation_code'") or die();
            $n = 0;
            while ($row = mysqli_fetch_object($query)) {
                $result[$n]['StartDate'] = $row->StartDate;
                $result[$n]['EndDate'] = $row->EndDate;
                $result[$n]['State'] = $row->State;
                $n++;
            }
            return $result;
        }
    }
}

和client.php

<?php

require 'lib/nusoap.php';
include 'functions.php';

$sessionid          = '1234';
$accommodation_code = '83081';

$client = new nusoap_client("http://192.168.8.155:8090/ws/service.php?wsdl");

$availabilities = $client->call(
    'getAvailabilities', 
    array(
        "SessionID"       => "$sessionid", 
        "AccommodationId" => "$accommodation_code",
    )
);

if ($client->fault) {
    echo 'Fault';
} else {
    $err = $client->getError();
    if ($err) {
        echo $err;
    } else {
        print_r($servicetypes);
    }
}
?>

如果我直接调用 getAvailabilities() 方法,它可以工作,但不能通过 Web 服务,任何帮助将不胜感激,谢谢。

4

0 回答 0