Soap 服务器在 Laravel 5.2 中不工作

Soap server not working in Laravel 5.2

我正在尝试在 laravel 5.2 中创建一个 soap 服务器。这是我的代码:
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}";
    }
}

我的 wsdl 文件是:wsdl

还有我的routes

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

结果我得到:

Internal Server Error

:(
我使用 piotrooo/wsdl-creator 生成 wsdl。 (这没有问题,它在 laravel 4.2 中工作)。我也尝试过 nusoap 和 php2wsdl 库。
我的 SoapClient 运行良好。因为它可以从其他 url 中的其他 soap 服务器获取服务,但是我认为我的 SoapServer 不能正常工作。
我什至在错误日志文件中没有发现任何错误。

不要在一个文件中使用两个 class 这是我在使用 Soap 的项目中的经验 这是 SoapServerController 。将 wsdl 文件粘贴到项目的根文件夹中

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

并在请求中为这样的请求创建 class:

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

并且路线必须是 post:

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

我刚刚弄清楚问题出在哪里:
日志的问题是我正在检查我的 www 文件夹中的错误日志,而 laravel 有自己的日志文件。使用它我发现我对 TokenMismatchException 有疑问。 Laravel 的 CsrfVerifyMiddleware 不允许我使用 soap 请求。
我刚刚将 url 添加到 CsrfVerifyMiddleware 文件中的 "except" 数组。

在laravel 5中,所有的before语句都变成了中间件(就像django框架中的一样)。并且你需要使用中间件来实现。