I installed nusoap on laravel 5.6 and am trying to connect my SOAP client with my SOAP server. I installed the package in the "require econea / nusoap-dev-develop" composer.
My route is this:
Route :: get ('/ client', 'SOAP \ ClientController @ client'); Route :: any ('/ server', 'SOAP \ ServerController @ server');
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;
}
}
}
}
This is my ServerController:
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'));
}
}
And this is the answer from my 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
Error Response not of type text/xml: text/html; charset=UTF-8
I'm using port 8080 pro server and port 8000 pro client.
Thank you.