Laravel 5.1 consuming soap wsdl service using controller and model

主宰稳场 提交于 2019-12-24 12:44:33

问题


Currently I'm using php and nusoap and wanted to convert it to Laravel.

When creating the soap calls I use data out of a mysql database.

So I think I would need a model (to get my data) and a controller (to create request).

EDIT:

<?php
namespace App\Http\Controllers;
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
class SoapController extends Controller {
public function demo()
{
// Add a new service to the wrapper
    SoapWrapper::add(function ($service) {
       $service
       ->name('currency')
       ->wsdl('path/to/wsdl')
       ->trace(true);
       ->options(['user' => 'username', 'pass' => 'password']);
     });

// Using the added service
SoapWrapper::service('currency', function ($service) {
var_dump($service->getFunctions());
var_dump($service->call('Otherfunction'));
});
}
}

from laravel-soap I couldn't find a tutorial on how to send login parameters prior to any other request. In the example 'using the added service' I see the login credentials but it doesn't work.


回答1:


This is how I got soap to work in Laravel 5.1

  1. clean install laravel 5.1
  2. install artisaninweb/laravel-soap
  3. create a controller SoapController.php

    <?php
    namespace App\Http\Controllers;
    use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
    class SoapController extends Controller {
    public function demo()
    {
    // Add a new service to the wrapper
        SoapWrapper::add(function ($service) {
           $service
           ->name('currency')
           ->wsdl('path/to/wsdl')
           ->trace(true);
         });
    $data = [
             'user' => 'username',
             'pass'   => 'password',
            ];
    // Using the added service
    SoapWrapper::service('currency', function ($service) use ($data) {
    
    var_dump($service->call('Login', [$data]));
    var_dump($service->call('Otherfunction'));
    });
    }
    }
    
  4. Create a route in your routes.php

Route::get('/demo', ['as' => 'demo', 'uses' => 'SoapController@demo']);

If requered you can also use the model extension as described here



来源:https://stackoverflow.com/questions/33314045/laravel-5-1-consuming-soap-wsdl-service-using-controller-and-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!