2017-09-11 22 views
0

私はこのような構造でリクエストを取得しようとしています:ここでPHP SOAPクライアント

<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コードです:

$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")); 

しかし、PHPは無効なXMLを生成:

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

オブジェクトウェイで有効なXMLを作成するにはどうすればよいですか?

答えて

1

同じ問題が発生する人のために。 私の解決方法は、ヌーサップ(https://github.com/yaim/nusoap-php7)を使用することです。このライブラリを使用すると、SWA(SOAP with Attachments)などの複雑な要求を行うことができます。 ここに私の質問のための作業コードがあります:

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

P.S.私はいくつかのジェネレータを試してきましたが、クラスは正しく生成されましたが、誰も正しいリクエストを行うことはできませんでした。

0

確実に、PackageGeneratorなどのPHPジェネレータにWSDLを使用する必要があります。

リクエストの作成、レスポンス処理が楽になります。

+0

答えをいただきありがとうございますが、動作しませんでした。私はこれが継承のためだと思う。 PackageGeneratorは抽象クラスreportParamsとクラスpersonCreditReportParamsを作成しましたが、personCreditReportParamsクラスの変数を渡している間は要素を作成しません。 –

+0

この場合、SoapClientオブジェクトは、実際に送信される前にXMLリクエストを変更するには、https://github.com/WsdlToPhp/PackageEws365/blob/develop/SoapClient/SoapClient.phpにあります。 https://github.com/WsdlToPhp/PackageEws365/blob/develop/generate.shの世代オプションを見てください。 –

関連する問題