doujiang3997 2015-10-28 08:16
浏览 70

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

I am currently working on a project that uses web service PHP Nusoap. I implement it at first in the local computer and it is already working perfectly fine, it can insert already in the database.Since, we are also deploying our project in the production server (Linux RHEL 4) so we also need to include the web service. In implementing this in the production server, we got this error :

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>

HERE IS THE CODE :

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


?>

what does this problem means and how can we solve this? Or how to setup the web service PHP Nusoap in the production server? Any ideas/suggestions is appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • dou5454954610 2016-05-05 16:08
    关注

    I'v had the same problem when PHP/Apache version changed at my server. Im my case the problem was located inside nusoap library function: parse_http_headers()

    There is a function used to get all HTTP headers getallheaders() and it seems not getting all headers as it should. There were no Content-Type which is required for nusoap to parse request (ex. text/xml).

    Fortunately nusoap checks if function getallheaders() exists and if not it uses $_SERVER array to parse headers.

    Finally the one thing I had to do was to change one line of code inside nusoap.php file to disable this function:

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

    to this one:

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

    Hope this help others!

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?