SOAP возвращает «Внутренняя ошибка сервера» - PullRequest
1 голос
/ 19 мая 2011

Мое SOAP-приложение, написанное на NuSOAP , возвращает ошибку http 500 (Internal Server Error).

На моем локальном компьютере работает нормально, эта ошибка появляется только в прямом эфире.

Как мне диагностировать эту ошибку?

Сервер:

require_once('nusoap.php');
// Create the server instance.
$server = new soap_server;
// Register the method to expose.
// Note: with NuSOAP 0.6.3, only method name is used without WSDL.
$server->register(
    'hello',                            // Method name
    array('name' => 'xsd:string'),      // Input parameters
    array('return' => 'xsd:string'),    // Output parameters
    'uri:helloworld',                   // Namespace
    'uri:helloworld/hello',             // SOAPAction
    'rpc',                              // Style
    'encoded'                           // Use
);
// Define the method as a PHP function.
function hello($name) {
 require_once 'classes.php';
 $db = new Database();
 $sql = "select * from notifications where skey = '$name'";
 $res = mysql_query($sql);
 $row = mysql_fetch_array($res);
    //return 'Hello, ' . $row['sales'];
    $ret = "<salesdat>
            <customername>". $row['sales']. "</customername>
         </salesdat>";
         return $ret;
}
// Use the request to (try to) invoke the service.
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);

Клиент:

// Pull in the NuSOAP code.
require_once('nusoap.php');
// Create the client instance.
$client = new soapclient('http://----my site url ---/server.php');
//$client = new soapclient('http://localhost/cb/server.php');
// Check for an error.
$err = $client->getError();
if ($err) {
    // Display the error.
    echo '<p><b>Constructor error: ' . $err . '</b></p>';
    // At this point, you know the call that follows will fail.
}
// Call the SOAP method.
$result = $client->call(
    'hello',                     // method name
    array('name' => 'shahidkari'),    // input parameters
    'uri:helloworld',            // namespace
    'uri:helloworld/hello'       // SOAPAction
);
// Strange: the following works just as well!
//$result = $client->call('hello', array('name' => 'Scott'));
// Check for a fault
if ($client->fault) {
    echo '<p><b>Fault: ';
    print_r($result);
    echo '</b></p>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error.
        echo '<p><b>Error: ' . $err . '</b></p>';
    } else {
        // Display the result.
        print_r($result);
    }
}

1 Ответ

0 голосов
/ 14 октября 2015

Это может произойти из-за ошибки php в вашем серверном скрипте. Включите сообщение об ошибке. Запустите сервер в браузере.

server.php

error_reporting(-1);
ini_set('display_errors', 'On');

require_once './src/Test.php';
$server = new SoapServer("https://xxxx/Outbound.wsdl");
$server->setClass('Test');
$server->handle();

https://xxxx/server.php // вызов этого в браузере приведет к ошибке.

В моем случае это было связано с require_once './src/Test.php';, который не включал класс.

...