[英]Help with NuSoap - Creation of web service
在過去的兩天里,我一直無奈地嘗試使用NuSoap在PHP中創建Web服務。 但是,在無休止地瀏覽各種教程和指南之后,我仍然停留在10行拒絕工作的代碼上。
服務器:
// Pull in the NuSOAP code
require_once('./lib/nusoap.php');
// Create the server instance
$server = new soap_server;
// Initialize WSDL support
$server->configureWSDL('hellowsdl','http://mysite.com');
// Register the method to expose
$server->register('hello',
array("params"=>"xsd:string"),
array("result"=>"xsd:string"),
'http://mysite.com'
);
// Define the method as a PHP function
function hello($name) {
return 'Hello, ' . $name;
}
// 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('./lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('http://localhost/nusoap/server.php?wsdl',true);
// Call the SOAP method
$result = $client->call('hello',array("name"=>"Scott"));
var_dump($result);
給我個布爾值(假)
我在哪里錯了?
注冊該方法時,您正在調用參數“ params”而不是“ name”,代碼應為:
$server->register('hello',
array("name"=>"xsd:string"),
array("result"=>"xsd:string"),
'http://mysite.com'
);
但是,您不應該出錯,當我運行帶有錯誤的代碼時,我仍然
string(12) "Hello, "
(空的$ name變量)。 轉到http://localhost/nusoap/server.php?wsdl並確保您可以在執行客戶端的同一台計算機上看到WSDL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.