notfalsedev / laravel-soap

A soap client wrapper for Laravel
MIT License
634 stars 122 forks source link

How to use __getLastRequest method #132

Closed waqas-mehmood-pk closed 6 years ago

waqas-mehmood-pk commented 6 years ago

My request:

$this->soapWrapper = new \Artisaninweb\SoapWrapper\SoapWrapper();
$this->soapWrapper->add( 'SoapService', function ( $service ) {
    $caCertificate = __DIR__ . "/Certificate/certificate.pem";
    $streamContext = stream_context_create( [ 'ssl' => [ 'cafile' => $caCertificate ] ] );
    $service->wsdl( "SoapServiceURL")
        ->options( [ 'stream_context' => $streamContext ] );
} );
$data = [ 'userId'   => 'id-1212121',
          'password' => 'id-password',
           'data'     => 'data', ];
$result = $this->soapWrapper->call( 'SoapService.method', [ $data ] );

after calling call method of soapWrapper i want to use __getLastRequest() Log::info( [ "XML response : " => $this->soapWrapper->__getLastRequest() ."\n" ] );

but whn i trying to call following error occured. Call to undefined method Artisaninweb\SoapWrapper\SoapWrapper::__getLastRequest()

nishpatel commented 6 years ago

That's not the correct way to use it.

Here is how to use it: $this->soapWrapper->client('SoapService', function ($client) { Log::info($client->getLastResponse()); });

JPedroMG commented 6 years ago

hi @nishpatel i tried to use the getlastrequest method in the way you said, but i have this error, could you help me with this? please!!!

Class 'App\Http\Controllers\cons\fina\cfem\Log' not found

this is my code

<?php

namespace App\Http\Controllers\cons\fina\cfem;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
use DataTables;
USE Carbon\Carbon;
use Artisaninweb\SoapWrapper\SoapWrapper;

class consfinacfemController extends Controller
{
 public function descargarCFD(request $request){

        $peticion="";

        $this->soapWrapper->add('Evento', function ($service) {
            $service
            ->wsdl('http://www.test.com.mx/php/wsv/wsv-srv.php?wsdl')
            ->trace(true)
            ->classmap([
                consultarTransporte::class
            ]);
        });

        // Without classmap
        $datosU=array(  'usuario'=>'',
                        'correo'=>'tech@terminal.com',
                        'password'=>'ter.01');

        $parametros=array(  'datosusuario'      => $datosU, 
                            'codigotransporte'  => '1', 
                            'transportista'     => '',
                            'placas'            => '');

        $response = $this->soapWrapper->call('Evento.consultarTransporte', [$parametros]);

        $peticion=$this->soapWrapper->client('Evento', function ($client) {
            Log::info($client->getLastRequest());
        });

        return response()->json(['codigo'=>200, 'datos'=>$response,'peticion'=>$peticion]);
    }
}
nishpatel commented 6 years ago

because Log is not declared! You need this:

use Illuminate\Support\Facades\Log;

For example...

JPedroMG commented 6 years ago

my bad, thank you!

JPedroMG commented 6 years ago

can i catch the response in the way i use it?

i getting "null" in the var $peticion

JPedroMG commented 6 years ago

@artisaninweb can you give me a piece of advice? please!

notfalsedev commented 6 years ago

Note: This method works only if the SoapClient object was created with the trace option set to TRUE. Source: http://php.net/manual/en/soapclient.getlastresponse.php

So add the option trace if you want to use the getLastResponse method.