linux - 如果使用 php nusoap 在 WSDL 中未定义操作,如何修复

标签 linux php web-services

我目前正在从事一个使用网络服务 PHP Nusoap 的项目。我首先在本地计算机上实现它,它已经运行良好,它已经可以插入数据库中。因为,我们也在生产服务器中部署我们的项目 (Linux RHEL 4) 所以我们还需要包括网络服务。在生产服务器中实现这个时,我们得到了这个错误:

Operation '' is not defined in the WSDL for this service Here is the full details :

<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
    <faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode>
    <faultactor xsi:type="xsd:string"></faultactor>
    <faultstring xsi:type="xsd:string">Operation &apos;&apos; is not defined in the WSDL for this service
    </faultstring>
    <detail xsi:type="xsd:string"></detail>
</SOAP-ENV:Fault>

这是代码:

client.php

<?php
    require_once('lib/nusoap.php');

    $data = json_decode(file_get_contents("php://input"), true);

    $file_name = $data['file_name'];
    $location = $data['location'];

    $client = new nusoap_client('http://servername:port/WebService/server.php?wsdl', true);

    if ($SERVER['REQUEST_METHOD'] == 'POST') {
        $err = $client->getError();

        if ($err) {
            echo "<h2> Constructor error </h2><pre>" . $err. "</pre>" ;
            echo "<h2> Debug </h2><pre>" . htmlspecialchars($client->getdebug(),        ENT_QUOTES) . "</pre>" ;
            exit();
        }

        $datas = array (
            'file_name' => $file_name,
            'location'   => $location
        );

        $result = $client->call('InsertData', $datas);

        if ($client->fault) {
            echo "<h2> Fault (Expect - The request contains an invalid SOAP Body)</h2> <pre>" ;
            print_r ($result);
            echo "</pre>";
        } else {
            $err = $client->getError ();
            if ($err) {
                echo "<h2> Error </h2><pre>" . $err.  "</pre>";
            } else {
                print_r ($result);
            }
        }
    } else if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        echo "Method is not POST " ;
    }

?>

server.php

<?php 
require_once('lib.nusoap');

$server = new soap_server();
$server->configureWSDL('Database Sample Insertion', 'urn:Insert');
$server->soap_defenconding = 'UTF-8' ;

$server->register('InsertData', 
    array (
        'file_name'  => 'xsd:file_name',
        'location'    => 'xsd:location'
    ),
    array ('return' => 'xsd:string'),
    'urn:Insert',
    'urn:Insertwsdl#InsertDate',
    'rpc',
    'literal'
);

function InsertData ($file_name, $location) {
    $db_host = 'localhost';
    $db_username = 'username';
    $db_password = '' ;
    $db_name = 'sample' ;

    $conn = new mysqli ($db_host, $db_username, $db_password, $db_name);

    if ($conn->connect_error) {
        trigger_error('Database connection failed : ' .$conn->connect_error , E_USER_ERROR);
    }

    $sql = "INSERT INTO transaction (`filename`, `location`) VALUES ('$file_name', '$location')";

    $query = $conn->query($sql);

}

    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '' ;
    $server->service($HTTP_RAW_POST_DATA);


?>

这个问题是什么意思,我们如何解决这个问题?或者如何在生产服务器中设置 web 服务 PHP Nusoap?任何想法/建议表示赞赏。谢谢

最佳答案

当我的服务器上的 PHP/Apache 版本发生变化时,我遇到了同样的问题。我的情况是问题出在 nusoap 库函数内:parse_http_headers()

有一个用于获取所有 HTTP header 的函数 getallheaders() 并且它似乎没有按预期获取所有 header 。没有 Content-Type 是 nusoap 解析请求所必需的(例如 text/xml)。

幸运的是,nusoap 检查函数 getallheaders() 是否存在,如果不存在,它使用 $_SERVER 数组来解析 header 。

最后我必须做的一件事是更改 nusoap.php 文件中的一行代码以禁用此功能:

if (function_exists('getallheaders')){ ... 

这个:

if (0 && function_exists('getallheaders')){ ...

希望这对其他人有帮助!

关于linux - 如果使用 php nusoap 在 WSDL 中未定义操作,如何修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33386545/

相关文章:

linux - 如果其中包含一些文本,请删除 html 标签

windows - Egit - 获取、 merge 、 pull 麻烦

php - Smarty 如何从 foreach 获取第一个索引?

php - 使用 PHP 在 WSDL 中使用奇怪的附加响应

linux - Expect:如何遍历目录中的文件?

linux - 使用 glob 表达式匹配两个整数

php - 获取目录中的文件

php - Doctrine 2 需要 Symfony 吗?

ios - 创建一个外部网络服务并在 viewdidload 中调用它

python - 选择使用 DAL 和 web2py 将 PostgreSQL 数据库连接到 Web 服务器