"SoapWrapper" does not work with laravel

0

I'm trying to consume a WS via application in laravel 5.6.

This is the test code:

namespace App\Http\Controllers;
use SoapClient;
use Artisaninweb\SoapWrapper\Facades\SoapWrapper;
use Illuminate\Http\Request;
use App\Soap\Request\GetConversionAmount;
use App\Soap\Response\GetConversionAmountResponse;
use App\Soap;
use App\Soap\Response;

class EducacionalController extends Controller{

protected $soapWrapper;

public function index(Request $request){
    $soap = SoapWrapper::add(function ($service) {
        $service
            ->name('rmFametro')
            ->wsdl('http://sistemas.portaledu.com.br:8051/wsConsultaSQL/MEX?wsdl')
            ->options([
                'login' => 'YYYYYYYY',
                'password' => 'XXXXXXXX'
            ])
            ->trace(true);
    });

     $response = $soap->soapWrapper->call('RealizarConsultaSQL', [
        'codSentenca' => '07', 
        'codColigada' => '1', 
        'codSistema'  => 'S', 
        'parameters'  => 'CPF=99999999999',
    ]);

    var_dump($response);

    }
}

And this is the test error:

  

Undefined property: Artisaninweb \ SoapWrapper \ Wrapper :: $ soapWrapper

My settings, in aap.php:

'providers' => [
...
Artisaninweb\SoapWrapper\ServiceProvider::class,
...
];

.

 'aliases' => [
 ...
 'SoapWrapper' => Artisaninweb\SoapWrapper\Facades\SoapWrapper::class
 ...     
 ];

Where can not I see an error?

    
asked by anonymous 24.05.2018 / 09:00

1 answer

1

Check the comments

//instancie um novo objecto
$soap = new SoapWrapper; 


//estava a  faltar o primeiro parâmetro 'rmFametro'
$soap->add('rmFametro', function ($service) {
    $service->wsdl('http://sistemas.portaledu.com.br:8051/wsConsultaSQL/MEX?wsdl')
        ->options([
            'login' => 'YYYYYYYY',
            'password' => 'XXXXXXXX'
        ])
        ->trace(true);
});

//verifique a forma correcta de efectuar a chamada
$response = $soap->call('rmFametro.RealizarConsultaSQL', [
    'codSentenca' => '07',
    'codColigada' => '1',
    'codSistema' => 'S',
    'parameters' => 'CPF=99999999999',
]);

var_dump($response);

Update using Controller

add the service provider in app / config / app.php.

Artisaninweb\SoapWrapper\ServiceProvider::class, 

add alias in app / config / app.php.

'SoapWrapper' => Artisaninweb\SoapWrapper\Facade\SoapWrapper::class,  

EducacionalController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Artisaninweb\SoapWrapper\SoapWrapper;

class EducacionalController extends Controller
{
    protected $soapWrapper;

    public function __construct(SoapWrapper $soapwrapper)
    {
        $this->soapWrapper = $soapwrapper;
    }
    public function index(Request $request)
    {
        $this->soapWrapper->add('rmFametro', function ($service) {
            $service->wsdl('http://sistemas.portaledu.com.br:8051/wsConsultaSQL/MEX?wsdl')
                ->options([
                    'login' => 'YYYYYYYY',
                    'password' => 'XXXXXXXX'
                ])
                ->trace(true);
        });

        $response = $this->soapWrapper->call('rmFametro.RealizarConsultaSQL', [
            'codSentenca' => '07',
            'codColigada' => '1',
            'codSistema' => 'S',
            'parameters' => 'CPF=99999999999',
        ]);

        var_dump($response);

    }

}
    
30.07.2018 / 23:47