0

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?

2 Answers 2

1

You should definitively use a WSDL to php generator such as PackageGenerator.

It'll ease you the request construction, the response handling.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, but it didn't work. I think this is because of inheritance. PackageGenerator created abstract class reportParams and class personCreditReportParams, but it does not create <reportParams xsi:type="ns1:personCreditReportParams"> element while I pass variable of personCreditReportParams class
in this case you can always override the SoapClient object using your own implementation such in github.com/WsdlToPhp/PackageEws365/blob/develop/SoapClient/… in order to alter the XML request before it is actually sent. Look to the generation options in github.com/WsdlToPhp/PackageEws365/blob/develop/generate.sh
1

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.

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.