[英]PHP SOAP webservice with NuSOAP gives no result if WSDL is configured
I have a php soap webservice which I've created with using NuSOAP. 我有一个使用NuSOAP创建的php soap网络服务。 I use the file 'test.php' to test it in the browser as ' http://www.mydowmain.com:8080/webservice/5/test.php '. 我使用文件“ test.php”在浏览器中以“ http://www.mydowmain.com:8080/webservice/5/test.php ”对其进行测试。
My code: 我的代码:
webservice.php webservice.php
<?php
require_once('../lib/nusoap.php');
$server = new nusoap_server();
$server ->configureWSDL('server', 'urn:server'); //this line causes to 'no result'
$server ->wsdl->schemaTargetNamespace = 'urn:server'; //this line causes to 'no result'
$server -> register('getData');
function getData ()
{
$items = array(array("item1"),array("item2"));
return $items;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server ->service($HTTP_RAW_POST_DATA);
?>
test.php test.php
<?php
require_once('../lib/nusoap.php');
$client = new nusoap_client("http://www.mydowmain.com:8080/webservice/5/webservice.php?wsdl");
$result = $client ->call('getData');
print_r($result);
?>
Problem: 问题:
If I remove these lines 如果我删除这些行
$server ->configureWSDL('server', 'urn:server');
$server ->wsdl->schemaTargetNamespace = 'urn:server';
it shows me the result fine. 它告诉我结果很好。 Otherwise I get a blank screen, get nothing. 否则我会出现黑屏,什么也没得到。 But I really need to configure the WSDL. 但是我确实需要配置WSDL。
How can I edit the webservice.php so that the WSDL will be configured and I can get the result array on the test.php ? 我如何编辑webservice.php以便配置WSDL并在test.php上获取结果数组?
To see error information about client you can add this : 要查看有关客户端的错误信息,您可以添加以下内容:
$result = $client->call('getData');
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2>' . $err;
// At this point, you know the call that follows will fail
exit();
}
else
{
echo $result;
}
After that, in the server.php, maybe the register needs more information about the return value. 之后,在server.php中,也许寄存器需要有关返回值的更多信息。
$server->register('getData',
array("response"=>"xsd:string"),
'http://www.mydowmain.com:8080'
);
Try changing this: 尝试更改此:
$server ->wsdl->schemaTargetNamespace = 'urn:server';
Into this: 变成这个:
$server ->wsdl->schemaTargetNamespace = $namespace;
and define $namespace on top of it. 并在其顶部定义$ namespace。 That did the trick for me. 那对我有用。
This is my code of my NuSOAP webservice: 这是我的NuSOAP Web服务的代码:
require_once("lib/nusoap.php");
$namespace = "http://localhost:8080/Testservice/service.php?wsdl";
$server = new soap_server();
$server->configureWSDL("TestService");
$server->wsdl->schemaTargetNamespace = $namespace;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.