Soap服务器无法在Laravel 5.2中运行

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Soap服务器无法在Laravel 5.2中运行相关的知识,希望对你有一定的参考价值。

我正在尝试在laravel 5.2中创建一个soap服务器。这是我的代码: SoapController.php的内容:

<?php namespace GiantHttpControllers;

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 WSDLWSDLCreator($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运行良好。因为它可以从其他网址中的其他soap服务器获得服务,但我认为我的SoapServer无法正常工作。 我甚至在错误日志文件中没有错误。

答案

我只知道问题是什么: 日志的问题是我在我的www文件夹中检查错误日志,而laravel有自己的日志文件。并使用我认为我有TokenMismatchException的问题。 Laravel的CsrfVerifyMiddleware不会让我要求使用肥皂。 我刚刚将我的url添加到CsrfVerifyMiddleware文件中的“except”数组中。

另一答案

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

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

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

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

和路线必须张贴:

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

另一答案

在laravel 5中,所有之前的语句都变成了中间件(就像django框架中的内容一样)。而且您需要使用中间件来实现。

以上是关于Soap服务器无法在Laravel 5.2中运行的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 5.2 版本在本地运行 laravel 项目

我将如何在后台运行 Laravel 5.2 的队列监听器?

Laravel 5.2 迁移:无法添加 char 数据类型的外键

无法在 laravel 5.2 中查询 json 数据

无法在 Laravel 5.2 中使用外键迁移

Laravel 5.2 忘记密码的模式弹出窗口显示 500 内部服务器错误,同时运行 ajax 功能