【问题标题】:Web Service NuSOAP laravel 4Web 服务 NuSOAP laravel 4
【发布时间】:2014-02-10 18:30:48
【问题描述】:

我正在使用 Laravel 4 中的 NuSOAP 开发 Web 服务。

我使用的类是https://github.com/noiselabs/NoiselabsNuSOAPBundle。

服务器

Route::any('ws/server', function()
{
    $server = new \soap_server;

    $server->configureWSDL('server.hello','urn:server.hello', Request::url());

    $server->wsdl->schemaTargetNamespace = 'urn:server.hello';

    $server->register('hello',
        array('name' => 'xsd:string'),
        array('return' => 'xsd:string'),
        'urn:server.hello',
        'urn:server.hello#hello',
        'rpc',
        'encoded',
        'Retorna o nome'
    );

    function hello($name)
    {
        return 'Hello '.$name;
    }

    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    return Response::make($server->service($HTTP_RAW_POST_DATA), 200, array('Content-Type' => 'text/xml; charset=ISO-8859-1'));
});

客户

Route::get('ws/client/hello', function()
{
    $client = new \nusoap_client('http://localhost/teste_laravel/public/ws/server?wsdl', true);

    $err = $client->getError();
    if ($err)
    {
        echo "Erro no construtor<pre>".$err."</pre>";
    }

    $result = $client->call('hello',array('Renato'));

    if ($client->fault)
    {
        echo "Falha<pre>".print_r($result)."</pre>";
    }
    else
    {
        $err = $client->getError();

        if ($err)
        {
            echo "Erro<pre>".print_r($err)."</pre>";
        }
        else
        {
            print_r($result);
        }
    }
});

返回此错误。

Array ( [faultcode] => SOAP-ENV:Client [faultactor] => [faultstring] => msg 解析错误:xml 为空,未解析![detail] => ) Falha 1

当我使用纯 PHP 服务器和正确的 Laravel 客户端时。

【问题讨论】:

    标签: php soap laravel-4 nusoap


    【解决方案1】:

    $HTTP_RAW_POST_DATA 并不总是根据您的 PHP 配置 (http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data) 填充。你可以试试这个:

    $rawPostData = file_get_contents("php://input");

    【讨论】:

    • 对!感谢您的提示!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    相关资源
    最近更新 更多