2016-05-13 4 views
0

私はPHPのSoapServerを使用しています。同じタイプの複数の項目を含めるようにします。このセクションのwsdlは次のようになります。 PHPでPHPを使用してSOAPレスポンスに同じタイプの複数のオブジェクトを含める方法

<xsd:element name="getSalesTaxResponse"> 
    <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element name="totalTaxAmount" type="xsd:string"></xsd:element> 
      <xsd:element maxOccurs="unbounded" minOccurs="1" name="productTax" type="tns:getSalesTaxResultInformation" /> 
      </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 
<xsd:complexType name="getSalesTaxResultInformation"> 
    <xsd:annotation> 
     <xsd:documentation>This object stores information related to product tax request 
     </xsd:documentation> 
    </xsd:annotation> 
    <xsd:sequence> 
     <xsd:element name="productId" type="xsd:string"></xsd:element> 
     <xsd:element name="productNRCPrice" type="xsd:string"></xsd:element> 
     <xsd:element name="taxAmount" type="xsd:string"></xsd:element> 
    </xsd:sequence> 
</xsd:complexType> 

私の脳が滞っていると私は私の人生のために応じて、複数の「productTax」レコードを含める方法を見つけ出すことはできません。私は現在これをやっていますが、私がしたいことはしません。

 $this->response = new GetSalesTaxResponse(); 
     $this->response->totalTaxAmount = '21.93'; 
     $this->response->productTax = array(
      (object) array(
       'productId'=>'3123', 
       'productNRCPrice'=>'201.20', 
       'taxAmount'=>'10.10'), 
      (object) array('productId'=>'2103', 
       'productNRCPrice'=>'102.10', 
       'taxAmount'=>'11.83') 
     ); 
     file_put_contents('/tmp/burp', print_r($this->response, TRUE), FILE_APPEND); 
     return $this->response->getSoapVar(); 

しかし、SOAP-UIではこれが表示されます。私はPHPでやっているものに基づいて理にかなっているが、どのように私は、代わりにこのように見えるようにPHPでの応答を構築するん

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.example.com/SOAP/Billing"> 
    <SOAP-ENV:Body> 
     <ns1:getSalesTaxResponse> 
     <totalTaxAmount>21.93</totalTaxAmount> 
     <productTax> 
      <SOAP-ENC:Struct> 
       <productId>3123</productId> 
       <productNRCPrice>201.20</productNRCPrice> 
       <taxAmount>10.10</taxAmount> 
      </SOAP-ENC:Struct> 
      <SOAP-ENC:Struct> 
       <productId>2103</productId> 
       <productNRCPrice>102.10</productNRCPrice> 
       <taxAmount>11.83</taxAmount> 
      </SOAP-ENC:Struct> 
     </productTax> 
     </ns1:getSalesTaxResponse> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.example.com/SOAP/Billing"> 
     <SOAP-ENV:Body> 
      <ns1:getSalesTaxResponse> 
      <totalTaxAmount>21.93</totalTaxAmount> 
      <productTax> 
        <productId>3123</productId> 
        <productNRCPrice>201.20</productNRCPrice> 
        <taxAmount>10.10</taxAmount> 
       </productTax> 
       <productTax> 
        <productId>2103</productId> 
        <productNRCPrice>102.10</productNRCPrice> 
        <taxAmount>11.83</taxAmount> 
      </productTax> 
      </ns1:getSalesTaxResponse> 
     </SOAP-ENV:Body> 
    </SOAP-ENV:Envelope> 

答えて

1

新しい複合型あなたのgetSalesTaxResponse用途を作成し、getSalesTaxResultInformationの配列型を持つ要素の配列を有する必要があり、PHP内から複合型の配列を設定するには:

<complexType name="getSalesTaxResultInformation_Array"> 
    <complexContent> 
    <restriction base="SOAP-ENC:Array"> 
     <sequence> 
     <element name="productTax" type="tns:getSalesTaxResultInformation" 
       maxOccurs="unbounded"/> 
     </sequence> 
    </restriction> 
    </complexContent> 
</complexType> 

これは次のようにgetSalesTaxResponseを行います

<xsd:element name="getSalesTaxResponse"> 
    <xsd:complexType> 
      <xsd:sequence> 
      <xsd:element name="totalTaxAmount" type="xsd:string"></xsd:element> 
      <xsd:element maxOccurs="unbounded" minOccurs="1" name="productTax" type="tns:getSalesTaxResultInformation_Array" /> 
      </xsd:sequence> 
    </xsd:complexType> 
</xsd:element> 

これが与えられるのSoapServerユーザーの入力をうまくするのに十分な情報をこれが動作しているように見える

$array_element = new SoapVar($response_array, SOAP_ENC_OBJECT, null, null, 'getSalesTaxResultInformation'); 
+0

、しかし:Rの配列データは、のSoapServerは、右の配列要素の型が見つからない場合は、getSalesTaxResultInformationに自分自身を各productTax行をキャストする必要があります、基本的にマップ

です検証エラーが発生しました。 src-resolve.4.2:コンポーネント 'soapenc:Array'の解決でエラーが発生しました。 'soapenc:Array'は 'http://schemas.xmlsoap.org/soap/encoding/'という名前空間にありますが、この名前空間のコンポーネントはスキーマ文書から参照できません。これを定義に追加しました:xmlns:soapenc = "http://schemas.xmlsoap.org/soap/encoding/" – Halfstop

関連する問題