【问题标题】:PHP Fatal error: Call to undefined method soapclient::_call()PHP致命错误:调用未定义的方法soapclient::_call()
【发布时间】:2018-04-15 04:36:06
【问题描述】:

我正在使用 SOAP 服务来上传图片,当我使用 web 服务上传图片时出现此错误。我对 php 和 SOAP webservices 没有太多经验,所以我会感谢任何帮助。我正在使用一个 php 库调用它nusoap。这是我的代码:

server.php

require_once('lib/nusoap.php'); //include required class for build nnusoap web service server

// Create server object
$server = new soap_server();

// configure  WSDL
$server->configureWSDL('Upload File', 'urn:uploadwsdl');

// Register the method to expose
$server->register('upload_file',                                 // method
array('file' => 'xsd:string','location' => 'xsd:string'),    // input parameters
array('return' => 'xsd:string'),                             // output parameters
'urn:uploadwsdl',                                            // namespace
'urn:uploadwsdl#upload_file',                                // soapaction
'rpc',                                                       // style
'encoded',                                                   // use
'Uploads files to the server'                                // documentation
);

// Define the method as a PHP function

function upload_file($encoded,$name) {
$location = "uploads\\".$name;                               // Mention where to upload the file
$current = file_get_contents($location);                     // Get the file content. This will create an empty file if the file does not exist     
$current = base64_decode($encoded);                          // Now decode the content which was sent by the client     
file_put_contents($location, $current);                      // Write the decoded content in the file mentioned at particular location      
if($name!="")
{
    return "File Uploaded successfully...";                      // Output success message                              
}
else        
{
    return "Please upload a file...";
}
}

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

cliente.php

require_once('lib/nusoap.php'); //include required class for build nnusoap web service server
$wsdl="http://{servidor}/WebServiceSOAP/server.php?wsdl";  // SOAP Server

if($_POST["submit"])
{
  $tmpfile = $_FILES["uploadfiles"]["tmp_name"];   // temp filename
  $filename = $_FILES["uploadfiles"]["name"];      // Original filename

  $handle = fopen($tmpfile, "r");                  // Open the temp file
  $contents = fread($handle, filesize($tmpfile));  // Read the temp file
  fclose($handle);                                 // Close the temp file

  $client=new soapclient($wsdl) or die("Error");   // Connect the SOAP server
  $response = $client->_call('upload_file',array($filename)) or die("Error");  //Send two inputs strings. {1} DECODED CONTENT {2} FILENAME
}   

//$client=new soapclient($wsdl) or die("Error");   // Connect the SOAP server
//$response = $client->__call('upload_file',array($decodeContent,$filename)) or die("Error");  //Send two inputs strings. {1} DECODED CONTENT {2} FILENAME

// Check if there is anny fault with Client connecting to Server
if($client->fault){
  echo "Fault {$client->faultcode} <br/>";
  echo "String {$client->faultstring} <br/>";
}
else{
print_r($response); // If success then print response coming from SOAP Server
}
<form name="name1" method="post" action="" enctype="multipart/form-data">
   <input type="file" name="uploadfiles"><br />
   <input type="submit" name="submit" value="uploadSubmit"><br />
</form>

当我按下上传按钮时出现此错误。这是我的错误日志:

错误日志”

[14-Apr-2018 22:44:57 America/Chicago] PHP Notice:  Undefined index: submit in /home/XXXX/public_html/WebServiceSOAP/client.php on line 5
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice:  Undefined variable: client in /home/XXXX/public_html/WebServiceSOAP/client.php on line 22
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice:  Trying to get property of non-object in /home/XXXX/public_html/WebServiceSOAP/client.php on line 22
[14-Apr-2018 22:44:57 America/Chicago] PHP Notice:  Undefined variable: response in /home/XXXX/public_html/WebServiceSOAP/client.php on line 27
[14-Apr-2018 22:45:05 America/Chicago] PHP Fatal error:  Call to undefined method soapclient::_call() in /home/XXXX/public_html/WebServiceSOAP/client.php on line 15

【问题讨论】:

    标签: php web-services soap nusoap


    【解决方案1】:

    您的代码中几乎没有问题

    1. 在第 5 行,您必须使用 isset 函数来检查提交。
    2. 调用方法前面有 2 个下划线 (_) (Magic function in php)
    3. 还有其他小错误,如 $client 未提交请求将不会被定义。

    【讨论】:

    • 我使用 2 个下划线和相同的错误:[14-Apr-2018 23:54:34 America/Chicago] PHP 致命错误:调用 /home/XXXXX 中未定义的方法 soapclient::__call() /public_html/WebServiceSOAP/client.php 第 15 行
    • __call 直接被弃用,而您必须使用 __soapCall 方法。在Official Docs 中指定
    • 我得到同样的错误.....[15-Apr-2018 00:05:35 America/Chicago] PHP 致命错误:调用 /home/ 中未定义的方法 soapclient::__soapCall() XXXX/public_html/WebServiceSOAP/client.php 第 17 行
    【解决方案2】:

    只需启用soap扩展即可解决问题。

    打开 php.ini 并将 ;extension=soap 更改为 extension=soap。保存更改并重新启动 Apache 服务器。

    【讨论】:

      猜你喜欢
      • 2015-05-13
      • 1970-01-01
      • 2013-06-02
      • 2011-07-17
      • 2015-04-15
      • 1970-01-01
      • 2018-04-04
      • 1970-01-01
      • 2017-04-01
      相关资源
      最近更新 更多