Having a NuSOAP web service defined in an inline route closure function works great, but having it in a route closure controller does not.
Example: working
routes.php:
Route::any('api', function() {
require_once ('nusoap.php');
$server = new \nusoap_server();
$server->configureWSDL('TestService', false, url('api'));
$server->register('test',
array('input' => 'xsd:string'),
array('output' => 'xsd:string'),
);
function test($input){
return $input;
}
$rawPostData = file_get_contents("php://input");
return \Response::make($server->service($rawPostData), 200, array('Content-Type' => 'text/xml; charset=ISO-8859-1'));
});
SOAP Test Client
require_once('nusoap.php');
$client = new \nusoap_client('http://ift.tt/2fymHco', true);
$result = $client->call("test", "HelloWorld");
print_r($result); exit();
response
HelloWorld
This works as expected.
Example: not working
Moving the code to a dedicated controller breaks it:
routes.php:
Route::any('api', 'SoapController@server');
SoapController.php:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SoapController extends Controller {
public function server() {
require_once ('nusoap.php');
$server = new \nusoap_server();
$server->configureWSDL('TestService', false, url('api'));
$server->register('test',
array('input' => 'xsd:string'),
array('output' => 'xsd:string'),
);
function test($input){
return $input;
}
$rawPostData = file_get_contents("php://input");
return \Response::make($server->service($rawPostData), 200, array('Content-Type' => 'text/xml; charset=ISO-8859-1'));
}
}
SOAP Test Client
require_once('nusoap.php');
$client = new \nusoap_client('http://ift.tt/2fymHco', true);
$result = $client->call("test", "HelloWorld");
print_r($result); exit();
response
"method 'test' ('test') not defined in service('' '')
Steps To Reproduce:
- Install a fresh copy of Laravel v5.2.45
- Download the last NuSOAP version (v0.9.5)
- Define the route for the NuSOAP Web Service - copy and paste the code from above
- Create the SoapController - copy and paste the code from above
- Create a new temp route to act as the SOAP client, and copy and paste the code beneath SOAP Test Client above into this route's closure function
- Load the temp route page in the browser to execute a SOAP call to the Web Service
Conclusion:
This indicates, that for some reason, the output is different when using an inline route function versus using a dedicated route controller.
How could this be?
Your insight greatly appreciated:
If you have:
- any experience with this and you have a solution
- or, you have an idea on why this could occur
- or, you have any thoughts on why having the NuSOAP code in the controller generates a different response than having it in an inline route function
...please chime in.
Thank you for your thoughts!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire