具有复杂类型的PHP Soap客户端

具有复杂类型的PHP Soap客户端,php,object,soap,soap-client,Php,Object,Soap,Soap Client,我正在尝试使用以下结构获取请求: <SOAP-ENV:Body> <ns1:getCreditReportTypes> <reportTypeRequest> <reportParams xsi:type="ns1:personCreditReportParams"> <personId>4</personId> <consentConfirmed>true

我正在尝试使用以下结构获取请求:

<SOAP-ENV:Body>
  <ns1:getCreditReportTypes>
    <reportTypeRequest>
      <reportParams xsi:type="ns1:personCreditReportParams">
        <personId>4</personId>
        <consentConfirmed>true</consentConfirmed>
      </reportParams>
    </reportTypeRequest>
  </ns1:getCreditReportTypes>
</SOAP-ENV:Body>
但是,php生成的xml无效:

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

真的
4.

如何使用对象方式生成有效的XML?

您应该明确使用WSDL到php生成器,例如


它将简化请求构造和响应处理。

您应该明确使用WSDL到php生成器,例如


它将简化请求构造和响应处理。

对于那些遇到相同问题的人。 我的解决方案是使用nusoap()。这个库允许您进行复杂的请求,包括SWA(带附件的SOAP)。 以下是我的问题的工作代码:

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

另外,我已经尝试了一些生成器,但是没有人能够提出正确的请求,尽管类是正确生成的。

适用于那些遇到同样问题的人。 我的解决方案是使用nusoap()。这个库允许您进行复杂的请求,包括SWA(带附件的SOAP)。 以下是我的问题的工作代码:

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

另外,我试过一些生成器,虽然类生成正确,但没有人能提出正确的请求。

谢谢你的回答,但它不起作用。我认为这是因为继承。PackageGenerator创建了抽象类reportParams和类personCreditReportParams,但在我传递personCreditReportParams Classis变量时,它不会创建元素。在这种情况下,您可以始终使用自己的实现重写SoapClient对象,以便在实际发送XML请求之前对其进行更改。感谢您的回答,请查看生成选项,但它不起作用。我认为这是因为继承。PackageGenerator创建了抽象类reportParams和类personCreditReportParams,但在我传递personCreditReportParams Classis变量时,它不会创建元素。在这种情况下,您可以始终使用自己的实现重写SoapClient对象,以便在实际发送XML请求之前对其进行更改。查看中的生成选项