如何解决NuSOAP中未在service('''')''中定义的“方法''('')错误?

时间:2019-09-16 07:51:45

标签: php soap wsdl nusoap

我正在为我的Web服务使用WSDL。我为此使用NuSOAP。首先,我得到NuSOAP文件夹。然后创建一个PHP文件。

<?php
require_once "lib/nusoap.php";
$JSON= array();
class TryFunc {
    public function A($a1,$a2,$a3,$o1) 
    {
    include "../conf/database.php";
    $SQL = "SELECT * FROM table_users";  
    $SQLResult=mysqli_query($conn,$SQL);
    while($row=mysqli_fetch_assoc($SQLResult))
    {
        $JSON[] = $row;
    }
    header('Content-Type: application/json; charset=utf-8');
    echo json_encode($JSON,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
    }

$server = new soap_server();
$server->configureWSDL("TryFunc", "MyURL");
  $server->wsdl->addComplexType('A',
    'complexType',
    'struct',
    'all',
    '',
    array(
            'a1' => array('name' => 'a1', 'type' => 'xsd:string'),
            'a2' => array('name' => 'a2', 'type' => 'xsd:string'),
            'a3' => array('name' => 'a3', 'type' => 'xsd:int'),
            'o1' => array('name' => 'o1', 'type' => 'xsd:string'),
    )
);
$server->register('A',                   
  array('a1' => 'xsd:string', 'a2' => "xsd:string",'a3' => "xsd:int",'o1' => "xsd:string"),      
   array("return" => "xsd:string"),
    "",
    "",
    "document",
    "literal",
    "document");

@$server->service(file_get_contents("php://input"));

之后,我为WSDL创建了一个客户端。

<?php
require_once "lib/nusoap.php";

$client = new nusoap_client("MyURL?wsdl", true);
$error  = $client->getError();

if ($error) {
    echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
  $result = $client->call("TryFunc.A",array("a1" => "AA","a2" => "B","a3" => "1","o1" => "C"));

if ($client->fault) {
    echo "<h2>Fault</h2><pre>";
    print_r($result);
    echo "</pre>";
} else {
    $error = $client->getError();
    if ($error) {
        echo "<h2>Error</h2><pre>" . $error . "</pre>";
    } else {
        echo "<h2>Main</h2>";
        echo $result;
    }
}
echo "<h2>Request</h2>";
echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
echo "<h2>Response</h2>";
echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";

我使用SoapUI进行测试。我可以成功调用我的URL,然后看到函数A。但是,当我想响应此函数时,会出现以下错误:

  

方法'A'('A')未在   service(''))

我找到了很多解决方案,但是没有用。我在这里申请是因为我不完全知道。我该如何解决这个问题?

0 个答案:

没有答案