我用NuSOAP编写的SOAP应用程序返回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);
}
}
答案 0 :(得分:0)
这可能是由于您的服务器脚本中的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';
不包括课程。