Search code examples
phpobjectsoapsoap-client

PHP Soap client with complex types


I am trying to get request with this structure:

<SOAP-ENV:Body>
  <ns1:getCreditReportTypes>
    <reportTypeRequest>
      <reportParams xsi:type="ns1:personCreditReportParams">
        <personId>4</personId>
        <consentConfirmed>true</consentConfirmed>
      </reportParams>
    </reportTypeRequest>
  </ns1:getCreditReportTypes>
</SOAP-ENV:Body>

Here is my php-code:

$obj = new \stdClass();
$obj->personId = 4;
$obj->consentConfirmed = true;
$data = new \SoapVar($obj, SOAP_ENC_OBJECT, "personCreditReportParams", $namespace, "reportParams");
$res = $this->client->getCreditReportTypes(new \SoapParam($data,"reportTypeRequest"));

However, php generates invalid xml:

<SOAP-ENV:Body>
  <ns1:getCreditReportTypes xsi:type="ns1:personCreditReportParams">
    <consentConfirmed>true</consentConfirmed>
    <personId>4</personId>
  </ns1:getCreditReportTypes>
</SOAP-ENV:Body>

How can I make a valid XML with object-way?


Solution

  • For those who'll get the same problem. My solution is to use nusoap (https://github.com/yaim/nusoap-php7). This library allows you to make complicated requests, including SWA (SOAP with Attachments). Here is working code for my question:

    $person = array("personId"=>$id, "consentConfirmed"=>$confirmed);
    $data = array(
      "reportParams"=>new soapval("reportParams", "personCreditReportParams", $person, false, $namespace)
    );
    $result = $client->call("getCreditReportTypes", $data, $namespace);
    

    P.S. I've tried some generators and no one could make correct request, although classes were generated correctly.