1

過去 2 日間、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);

bool(false) を返す

どこが間違っているのですか???

4

1 に答える 1

1

メソッドを登録するとき、パラメータ「name」ではなく「params」を呼び出しています。コードは次のようになります。

$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 が表示されることを確認します。

于 2010-12-07T01:29:47.887 に答える