I'm using PHP's SoapServer and I want the response to include multiple items of the same type. My wsdl for this section looks like this.
<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>
In PHP my brain is stuck and I can't for the life of me figure out how to include multiple "productTax" records in the response. I'm currently doing this, but it doesn't do what I want.
$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();
But in SOAP-UI, I see this.
<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>
That makes sense based on what I'm doing in PHP, but how do I build the response in PHP to look like this instead?
<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>