Question

I am developing a web service with NuSOAP in Laravel 4.

The class that I'm using is https://github.com/noiselabs/NoiselabsNuSOAPBundle.

Server

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

Client

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

This error is returned.

Array ( [faultcode] => SOAP-ENV:Client [faultactor] => [faultstring] => error in msg parsing: xml was empty, didn't parse! [detail] => ) Falha 1

When I do with pure PHP server and the client with the right Laravel.

Was it helpful?

Solution

$HTTP_RAW_POST_DATA is not always populated depending on your PHP config (http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data). You could try this instead:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top