1

Firstly I would like to apologise if this issue has come up already in Stack Overflow but my googling did not manage to find it.

I'm running on PHP 7.2 and have created a SoapClient to send RPC encoded requests to a Web Service.

$this->client = new \SoapClient('https://tsp.demo.sk.ee/dds.wsdl', [
    'soap_version' => SOAP_1_1,
    'cache_wsdl' => WSDL_CACHE_NONE,
    'trace' => true,
    'style' => SOAP_RPC,
    'use' => SOAP_ENCODED,
]);

I now tried to use this client to send a request to the MobileAuthenticate request and use named parameters to do it since I don't need to fill in all of the available parameters.

$params = [
    'CountryCode' => 'EE',
    'PhoneNo' => '+3xxxxxxxxxx',
    'Language' => 'ENG',
    'ServiceName' => 'Testimine',
    'MessageToDisplay' => 'Test Message',
    'SPChallenge' => '12345678901234567890',
    'MessagingMode' => 'asynchClientServer',
];


try {
    $response = $this->client->MobileAuthenticate($params);
    dd($response);
} catch (\SoapFault $e) {
    var_dump($e);
    var_dump($this->client->__getLastRequest());
    var_dump($this->client->__getLastResponse());
}

I was getting back that the language code was incorrect but based on the Web Service documentation, it was. I then started examining the output of $this->client->__getLastRequest() and found out that the method call was taking the parameters in an ordered array fashion. It set the first parameter value as Array.

I examined the SoapFault exception output and indeed, my named parameters were nested in another array

["args"]=>
  array(2) {
    [0]=>
    string(18) "MobileAuthenticate"
    [1]=>
    array(1) {
        [0]=>
      array(8) {
            ["IDCode"]=>
        string(0) ""
            ["CountryCode"]=>
        string(2) "EE"
            ["PhoneNo"]=>
        string(12) "+3xxxxxxxxxx"
            ["Language"]=>
        string(3) "ENG"
            ["ServiceName"]=>
        string(9) "Testimine"
            ["MessageToDisplay"]=>
        string(12) "Test Message"
            ["SPChallenge"]=>
        string(20) "12345678901234567890"
            ["MessagingMode"]=>
        string(18) "asynchClientServer"
      }
    }
  }

I've tried googling for similar issues and everything I found (even comments on php.net) show that this is the way to use named parameters, even most nowadays services expect the usage of named parameters.

Several months back I worked on another project running on PHP 5.6 that also consumed a SOAP Web Service and that worked like a charm. SoapClient implementation-wise, the only difference I see is the PHP version.

Am I missing something that has changed since PHP 7 that I can't see in the docs or I'm blindly not seeing the issue?

Small update: I was able to reproduce the issue on Homebrew compiled PHP 5.6, 7.0 and 7.2 as well as on Arch Linux compiled PHP 7.2.

3
  • Possibly related: bugs.php.net. You might try adding 'features' => SOAP_SINGLE_ELEMENT_ARRAYS or 'features' => SOAP_USE_XSI_ARRAY_TYPE or both. Commented Mar 25, 2018 at 10:55
  • @billynoah I did give a try with SOAP_SINGLE_ELEMENT_ARRAYS before but it had no affect. I now tried the combination of the two and unfortunately the result was the same. Commented Mar 25, 2018 at 14:07
  • was just a thought. it's most likely a conflict between php soapclient implementation and your wsdl. But it's interesting that what he describes in that bug report is exactly what you experienced. did you try SOAP_USE_XSI_ARRAY_TYPE by itself? Commented Mar 25, 2018 at 14:12

1 Answer 1

1

I was able to solve this issue by not using magic methods and using __soapCall instead which seems to behave properly to named parameters.

$response = $this->client->__soapCall('MobileAuthenticate', $params);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.