[英]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运行良好。 因为它可以从其他网址中的其他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('App\\Http\\Requests\\somenamespace\\SoapRequest'); $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框架中一样)。 而且您需要使用中间件来实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.