SOAP 返回“内部服务器错误”

发布于 2024-11-08 02:45:36 字数 2738 浏览 0 评论 0原文

我用 NuSOAP 编写的 SOAP 应用程序返回 http 500(内部服务器错误)错误。

它在我的本地计算机上运行良好,我只在实时情况下收到此错误。

我该如何诊断这个错误?

服务器:

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);
    }
}

My SOAP application written in NuSOAP returns an http 500 (Internal Server Error) error.

It is working fine on my local machine, I only get this error in live.

How do I diagnose this error?

Server:

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);

Client:

// 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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霊感 2024-11-15 02:45:36

这可能是由于服务器脚本中的 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'; 不包括该类。

This may due to the php error in your server script. Switch on the error reporting. Run the server in a browser.

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 // calling this in a browser will throw the error.

In my case it was due to require_once './src/Test.php'; which was not including the class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文