3

I'm trying to create a soap server in laravel 5.2. This is my code:
Content of SoapController.php:

<?php namespace Giant\Http\Controllers; class SoapController extends Controller { public function __construct() { parent::__construct(); ini_set('soap.wsdl_cache_enabled', 0); ini_set('soap.wsdl_cache_ttl', 0); ini_set('default_socket_timeout', 300); ini_set('max_execution_time', 0); } public function server() { $location = url('server'); // http://payment.dev/server $namespace = $location; $class = "\\Giant\\Http\\Controllers\\HelloWorld"; $wsdl = new \WSDL\WSDLCreator($class, $location); $wsdl->setNamespace($namespace); if (isset($_GET['wsdl'])) { $wsdl->renderWSDL(); exit; } $wsdl->renderWSDLService(); $wsdlUrl = url('wsdl/server.wsdl'); $server = new \SoapServer( url('server?wsdl'), array( 'exceptions' => 1, 'trace' => 1, ) ); $server->setClass($class); $server->handle(); exit; } public function client() { $wsdl = url('server?wsdl'); $client = new \SoapClient($wsdl); try { $res = $client->hello('world'); dd($res); } catch (\Exception $ex) { dd($ex); } } } class HelloWorld { /** * @WebMethod * @desc Hello Web-Service * @param string $name * @return string $helloMessage */ public function hello($name) { return "hello {$name}"; } } 

My wsdl file is: wsdl

And my routes:

Route::any('/server', 'SoapController@server'); Route::any('/client', 'SoapController@client'); 

And the result I get:

Internal Server Error 

:(
I use piotrooo/wsdl-creator to generate wsdl. (There is no problem with that, It is working in laravel 4.2). And I have also tried nusoap and php2wsdl libraries.
My SoapClient is working well. Because it can get service from other soap servers in other urls, But I think my SoapServer can not work well.
I even get no errors in error-log file.

1
  • is this a typo error or a small error you did not see that causes you script to fail? array( 'exceptions' => 1, 'trace' => 1, ) should be array( 'exceptions' => 1, 'trace' => 1 ). If this is why you get an error then i should convert this comment to an answer. Commented May 27, 2016 at 17:36

3 Answers 3

2

I just figured out wht was the problem:
The problem with log was that i was checking error-log in my www folder while laravel has its own log file. And using that i figured that i have problem with TokenMismatchException. Laravel's CsrfVerifyMiddleware would not letting me to request using soap.
I just added my url to "except" array inside CsrfVerifyMiddleware file.

Sign up to request clarification or add additional context in comments.

2 Comments

ooh, yeah, I forgot tell about it,sorry, the route must be in excpetion list
The soap calls are typically api calls, so use the routes/api.php route file. The api middleware is stateless and not use CSRF protection. laravel.com/docs/5.4/routing#basic-routing
1

Do not use two classes in one file This is my experience from our project in which used Soap This is SoapServerController . Paste wsdl file in root folder of your project

class SoapServerController extends Controller { public function service() { $server = new \SoapServer('http://' . request()->server('HTTP_HOST') . '/yourwsdlfile.wsdl'); $server->setClass('App\Http\Requests\somenamespace\SoapRequest'); $server->handle(); } }

and in requests create class for requests like this:

class SoapRequest{ public function functionFromWsdl($args if you want) { $parameters = (array) $args; return with(new fooClass())->barMethod($parameters); } }

and route must be post:

Route::post('webservice','SoapServerController@service');

7 Comments

Thank you @Faradox. But that did not help me. This is my controller, my wsdl, my SoapRequest class, my SoapClinet (in a pure php script). and my route: Route::any('webservice','SoapServerController@service');
I get "Internal server error" when i call method in soap server. And there is no log in error_log file and i do not know what is the cause of error.
I have also tried to call soap-server in non-wsdl mode. And the same problem.
problem with your wsdl
try like this in service method `` $server = new \SoapServer('http://' . request()->server('HTTP_HOST') . '/yourwsdlfile.wsdl');``
|
1
+100

In laravel 5 all before statements have turned into middlewares (just like what is in django framework). And you need to implement using middlewares.

1 Comment

I checked the laravel 5 documents. You are right @Sirbito. Thanks a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.