Laravel 5.1 consuming soap wsdl service using cont

2019-08-15 01:37发布

问题:

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