Search code examples
phpwsdlsoap-client

PHP SoapClient - _SoapCall having to wrap parameters inside method name


I have the following soap webservice:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
     <Customer_Get xmlns="http://example.com/">
       <token>string</token>
       <customerId>string</customerId>
     </Customer_Get>
   </soap:Body>
</soap:Envelope>

The following call doesn't work:

$soap = new SoapClient('link/to/.wsdl');
$result = $soap->__soapCall('Customer_Get', ['token' => 'asdad', 'customerId' => 1]);

However when I wrap the parameters array inside an array with the method name then it works:

$soap = new SoapClient('link/to/.wsdl');
$result = $soap->__soapCall('Customer_Get', ['Customer_Get' => ['token' => 'asdad', 'customerId' => 1]]); 

Why do i need to wrap the parameters inside the method name?


Solution

  • Because this call

    $result = $soap->__soapCall('Customer_Get', ['Customer_Get' => ['token' => 'asdad', 'customerId' => 1]]);
    

    is a shorthand for this call (with 'parameters') here:

    $result = $soap->__soapCall('Customer_Get', ['parameters' => ['Customer_Get' => ['token' => 'asdad', 'customerId' => 1]]]);