wsdl에서 정의 된 복합 형을 얻기 위해 PHP 서버에서 복잡한 유형을 얻으려고합니다.이 배열은 ConjuntAnimals로 정의됩니다. Animal 객체의 배열로 나타냅니다.PHP nusoap 호출은 complexType 배열 대신 bool false를 반환합니다.
그러나 내가 $result = $client->call('consulta_gossos', $params);
을 할 때 bool (false)이 반환됩니다. 나는 디버깅과 오랜 시간 동안 로깅을 해왔으며, 비누 연산 내에서 반환하기 직전에 그 값은 (반환되어야하는) 배열이지만, 클라이언트에서는 얻을 수 없다. 이것은 돌려 보냈다. (어쩌면 그것은 도움이 ... 또한
그것을 실현 후, 나는 내가 잘못 가지고있는 복합 타입 정의 어쩌면 생각하지만, 나는 많은 예제와 비교 한이이어야한다
[10-Dec-2016 12:59:11 America/New_York] PHP Catchable fatal error: Object of class stdClass could not be converted to string in /home/cabox/workspace/lib/nusoap.php on line 6132 [10-Dec-2016 12:59:11 America/New_York] Response not of type text/xml: text/html
나는 그것이 XML 응답을 기대 이해, 그래서 내가 대신 $gossos
의 json_encode($gossos)
을 반환하려고했지만, 다음이 기록합니다 :) 나는이 오류가 기록 얻을 [10-Dec-2016 13:11:34 America/New_York] XML error parsing SOAP payload on line 2: Invalid document end
나는 클라이언트와 서버 코드를 추가
클라이언트 : 들여 쓰기 죄송
`
<?php
require_once('./lib/nusoap.php');
$wsdl='http://php-ad-msk1416368101.codeanyapp.com/soapserver.php?wsdl';
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
$client = new nusoap_client($wsdl,'wsdl');
$client->encode_utf8 = false;
$client->decode_utf8 = false;
$client->soap_defencoding = 'utf-8';
$err = $client->getError();
if ($err) {
echo "Constructor error" . $err;
exit();
}
$edat = $_GET['edat'];
$raca = $_GET['raca'];
$vacunat = $_GET['vacunes'];
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
$result = $client->call('consulta_gossos', array('edat' => $edat, 'raca' => $raca, 'vacunat' => $vacunat));
$err = $client->getError();
error_log($err);
error_log(json_encode($result));
echo 'Type: '.gettype($result).', size: '.sizeOf($result);
?>
`
<?php
require_once('./lib/nusoap.php');
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log("Hello, errors!");
$server = new nusoap_server;
$server->soap_defencoding = 'utf-8';
$server->encode_utf8 = false;
$server->decode_utf8 = false;
$server->configureWSDL('server','urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->wsdl->addComplexType('Animal',
'complexType',
'struct',
'all',
'',
array(
'xip' => array('name' => 'xip', 'type' => 'xsd:int'),
'nom' => array('name' => 'nom', 'type' => 'xsd:string'),
'edat' => array('name' => 'edat', 'type' => 'xsd:int'),
'vacunat' => array('name' => 'vacunat', 'type' => 'xsd:string'),
'menjar' => array('name' => 'menjar', 'type' => 'xsd:string'),
'data_entrada' => array('name' => 'data_entrada', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType('ConjuntAnimals',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:Animal[]')
),
'tns:Animal'
);
$server->register('consulta_gossos',
array('edat' => 'xsd:string',
'raca' => 'xsd:string',
'vacunat' => 'xsd:string'),
array('return' => 'tns:ConjuntAnimals'), //output
'urn:server', //namespace
'urn:server#consulta_gossos', //SOAP action
'rpc',
'encoded',
'Consultar els gossos que compleixen el filtre');//description
function consulta_gossos($edat, $raca, $vacunat) {
$servername = 'localhost';
$username = 'root';
$password = 'root';
$dbname = 'bd_refugi';
$vacunes = ($vacunat =='si') ? 1 : 0;
$sql_edat = ($edat == 'gran') ? ' edat > 5 ' : ' edat <= 5 ';
$connection = new mysqli($servername, $username, $password, $dbname);
$sql = 'select * from gossos where '.$sql_edat.' and raca="'.$raca.'" and vacunat='.$vacunes;
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos->xip=$row['xip'];
$gos->nom=$row['nom'];
$gos->edat=$row['edat'];
$gos->vacunat=$row['vacunat'];
$gos->menjar=$row['menjar'];
$gos->data_entrada=$row['data_entrada'];
array_push($gossos,$gos);
}
error_log(json_encode($gossos));
error_log('-----------------------------------------');
return json_encode($gossos);
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
이, 내 눈을 복사 한 후 너무 출혈 여기에 코드를 붙여 넣으십시오.
편집 : 위에 표시된 오류를 제쳐두고 질문은 "올바른"배열을 반환하는 이유에 더 집중하려고합니다. 클라이언트에서 이러한 오류를 모두 없애면 빈 배열이 생깁니다.
비누를 사용한 적이 없으므로 오류를 해결할 수 없습니다 ...하지만 stdClass ...이 링크가 문제의 원인을 설명하는 데 도움이 될 수 있습니까? http://stackoverflow.com/questions/3607550/object-of-class-stdclass-could-not-be-converted-to-string –