laravel-soap icon indicating copy to clipboard operation
laravel-soap copied to clipboard

READ FIRST: Bug in usage of underlying SoapClient library!

Open jankal opened this issue 6 years ago • 5 comments

There is a documented difference between calling SoapClient::__call() and SoapClient::__soapCall()!

You can execute a remote SOAP function like $client->getApples(['number' => 10]); which results in the SOAP service being called according to the WSDL description.

But when using $client->__soapCall('getApples', ['number' => 10], ...); the WSDL is not being used. Therefor parameters have to be encapsulated into an additional array like this:

$client->__soapCall('getApples', ['parameters' => ['number' => 10]], ...);

(often it's called parameters)

This behaviour is also documented on php.net which states that __soapCall is of lower level functionality than __call (calling the method "overloaded" as if it was part of the class).

Reference comments on php.net: http://php.net/manual/en/soapclient.soapcall.php#89308 http://php.net/manual/en/soapclient.call.php#114787

This library uses the SoapClient class via __soapCall (see here). Therefor this behaviour should be documented in the README or even fixed by adding the encapsulating array automatically (needs debug).

Keep in mind: SoapClient::__call is acutally deprecated but everybody is used to it.

jankal avatar Apr 08 '18 10:04 jankal

I just banged my head hard to make the example work.

After doing as you told, I finally made it work.

// Without classmap
$response = $this->soapWrapper->call('Currency.GetConversionAmount', [
    'parameters' => [ // TODO this differs from the documentation
        'CurrencyFrom' => 'USD',
        'CurrencyTo'   => 'EUR',
        'RateDate'     => '2018-04-11T00:00:00',
        'Amount'       => '1000',
    ]
]);

tonila avatar Apr 11 '18 12:04 tonila

@tonila Thank you very much! It saves tons of my effort to make it work!

prcvoldermort avatar Aug 05 '20 03:08 prcvoldermort

@jankal Thank you so much for pointing out, that I need to place my parameters in an array item with ['parameters' => I was getting nuts trying to understand, why my parameters did not get passed into the XML request!

marventhieme avatar Aug 16 '20 17:08 marventhieme

@tonila thanks for that, super helpful

PaulKish avatar Nov 25 '20 13:11 PaulKish

For me, just wrapping in another array was enough, without the 'parameters' key. Please add comment to documentation for the non-classmap version as I banged my head for an hour on this.

marnickmenting avatar Jan 13 '22 11:01 marnickmenting