0

NuSOAP ライブラリを使用して PhP Web サービスを開発していましたが、エラーが発生しました。エラーが理解できませんでした。どなたか解決策をご存知の方、助けてください。以下は私のコードです。

------ server.php ------

<?php

// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the server instance
$server = new soap_server;

// Register the method to expose
$server->register('hello');

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

?>

------ client.php ------

<?php

// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance
$client = new nusoap_client('server.php');
// Check for an error
$err = $client->getError();

if ($err) 
{
   // Display the error
   echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
   // At this point, you know the call that follows will fail
}

// Call the SOAP method
$result = $client->call('hello', array('name' => 'Scott'));

// Check for a fault    
if ($client->fault) 
{
        echo '<h2>Fault</h2><pre>';
        print_r($result);
        echo '</pre>';
}
 else
 {

    // Check for errors
        $err = $client->getError();
        if ($err) 
    {
            // Display the error
            echo '<h2>Error</h2><pre>' . $err . '</pre>';
        }
     else 
     {
            // Display the result
            echo '<h2>Result</h2><pre>';
            print_r($result);
            echo '</pre>';
        }
}
?>

クライアントを実行すると、次のエラーが発生します。

Error

no transport found, or selected transport is not yet supported!
4

2 に答える 2

0

nusoap_client をインスタンス化する場合:

new nusoap_client('server.php');

あなたのコンストラクタパラメータ'server.php'は私には有効に見えません。これは有効なエンドポイントであるはずです:

ドキュメント

だから、あなたの「server.php」が実際にどこにあるか。client.php を実行している同じマシン上にある場合は、次のようになります。http://127.0.0.1/app/server.php

于 2012-09-29T06:24:24.130 に答える
0

NuSoap のドキュメントをもっと正確に読むべきだと思います。あなたのコードで見つけたいくつかの間違い:

  1. 配列がメソッドに渡され、hello メソッドに文字列パラメーター $name を使用しました。

    $name['name']; //is correct!
    
  2. クライアントは、HDD url(server.php) ではなく、いくつかのインスタンスまたは Web url を呼び出す必要があります。

    new nusoap_client(SOME_IP_OR_HOSTNAME . '/server.php'); //is correct!
    
    require_once 'server.php';
    new nusoap_client($server); //is correct!
    
    new nusoap_client(WSDL_INSTANCE_OBJECT); //is correct! 
    
    new nusoap_client('server.php'); //is incorrect!
    

詳細については、NuSoap のドキュメントを参照してください。

于 2012-09-29T06:40:21.633 に答える