Back

Nusoap doens't work in Laravel 5.6


AGNER SOUZA BEZERRA posted 7 months ago

I've installed the nusoap in laravel 5.6. I'm trying to connect my SOAP client to my SOAP serve. I've installed the package composer require econea/nusoap: dev-develop , this is my route:

Route::get('/client','SOAP\[email protected]');
Route::any('/server','SOAP\[email protected]');

This is my ClientController:

use App\Http\Controllers\Controller;
use nusoap_client;

class ClientController extends Controller
{public function client()
{
    $client = new nusoap_client('http://localhost:8080/index.php/server?wsdl');

    $response = $client->call('get_price','book');
    if ($client->fault) {
        echo "<h2>Fault</h2><pre>";
        print_r($response);
        echo "</pre>";
    } else {
        $error = $client->getError();
        if ($error) {
            echo "<h2>Error</h2><pre>" . $error . "</pre>";
        } else {
            echo "<h2>Main</h2>";
            echo $response;
        }
    }
}
}

And this is my ServidorController

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Response;
use nusoap_server;

class ServidorController extends Controller
{public function server()
{

    $server = new nusoap_server(); // Create a instance for nusoap server

    $server->configureWSDL("Soap Demo", "urn:soapdemo"); // Configure WSDL file

    $server->register(
        "get_price", // name of function
        array("name" => "xsd:string"),  // inputs
        array("return" => "xsd:integer")   // outputs
    );
    function get_price($name)
    {
        $products = [
            "book" => 20,
            "pen" => 10,
            "pencil" => 5
        ];

        foreach ($products as $product => $price) {
            if ($product == $name) {
                return $price;
                break;
            }
        }
    }

    return Response::make($server->service(file_get_contents("php://input")),
        200, array('Content-Type' => 'text/xml; charset=ISO-8859-1'));
}
}

This is the response server:

HTTP/1.0 419 unknown status
Host: 127.0.0.1:8080
Date: Tue, 08 May 2018 20:00:16 +0000
Connection: close
X-Powered-By: PHP/7.1.17-1+ubuntu16.04.1+deb.sury.org+1
Cache-Control: no-cache, private
date: Tue, 08 May 2018 20:00:16 GMT
Content-Type: text/html; charset=UTF-8
pragma: no-cache
expires: -1
Set-Cookie: laravel_session=eyJpdiI6ImlIemsxYzZnVWFhZDlxdEh5Q2FSU3c9PSIsInZhbHVlIjoiVjBkbFBXams1NGcyS1E3dlIrXC9hZ1BkXC9cLzdmTGlTa2NzVWxxS3RlK0o3aCtMM0lKaUxIbWxmRGc3SGdCWlM4bzYrSlMyMlhKelhiZEE4NU5rN3FVM0E9PSIsIm1hYyI6ImZkZmU1YjlmMWMwNTFlNGQ4NmMyMGViYTVhNWYxMjBiZGFkODcxMWI1Njg2NTRjMTQzMWQ4OTlkZTQ4MWVjM2UifQ%3D%3D; expires=Tue, 08-May-2018 22:00:16 GMT; Max-Age=7200; path=/; HttpOnly

Error Response not of type text/xml: text/html; charset=UTF-8


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us