PHP SOAP server + Javascript client

  javascript, node.js, php, soap

I have to communicate a Javascript application (NodeJS) with a PHP SOAP server. Right now, I’m using the soap package, which I’ve used in another projects (Java SOAP servers) successfully. However, I’m having some troubles this time trying to make both parts understand each other. I’ll show you an example of a request (I’ve simplified the code a bit):

import * as soap from 'soap';

const soapClient = await soap.createClientAsync(wsdlUrl);

async getUserByUsername(username: string) {
  const secret_key = await buildSecretKey();

  const response = await soapClient['WSGetUserFromUsernameAsync']({
  }, { timeout: 5000 });

  return response;

const user = await getUserByUsername('admin');

This doesn’t work because, when I see the logs on the PHP backend, these are the arguments it’s receiving, as shown in the log file:

$params: SECRET_KEY

As you can see, it’s receiving only the secret key parameter instead of the full object. However, if I call the SOAP method using PHP it works fine. I use the following (simplified) code:

$soap = new SoapClient($wsdlUrl);

$secret_key = buildSecretKey();

$result = $soap->WSGetUserFromUsername(array(
  'secret_key' => $secret_key,
  'username' => 'admin'

In this case, the log file shows the following parameters:

$params: Arrayn(n    [username] => adminn    [secret_key] => SECRET_KEYn)n

I think that the problem is that the data sent by the Javascript client (JSON) is not converted to the expected format by the server (a PHP associative array), but I’m not sure as I still didn’t have time to trace the request on the server and see what it’s receiving.

Anyway, any clue of what I could try? Thanks!

Source: Ask PHP