php SoapClient参数序列具有相同的名称

I've to do a soap call where the parameter contains a sequence of complex type.

I don't find the good format for the parameter.

Here the xsd :

<xs:complexType name="createOspService">
    <xs:sequence>
        <xs:element name="OSP" type="tns:OSP" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="ospServiceResponse">
</xs:complexType>
<xs:complexType name="OSP">
    <xs:sequence>
        <xs:element name="OSP_ID" type="xs:int" minOccurs="1" maxOccurs="1"/>
        <xs:element name="DATE_OSP" type="xs:dateTime" minOccurs="1" maxOccurs="1"/>
        <xs:element name="CUSTOMER_ID" type="xs:int" minOccurs="1" maxOccurs="1"/>
        <xs:element name="RECIPIENT_ID" type="xs:int" minOccurs="1" maxOccurs="1"/>
        <xs:element name="ITEMS" type="tns:ITEMS" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="ITEMS">
    <xs:sequence>
        <xs:element name="ITEM" type="tns:ITEM" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="ITEM">
    <xs:sequence>
        <xs:element name="OSP_ITEM" type="xs:string" minOccurs="1" maxOccurs="1"/>
        <xs:element name="QUANTITY" type="xs:double" minOccurs="1" maxOccurs="1"/>
        <xs:element name="UNIT_PRICE" type="xs:double" minOccurs="1" maxOccurs="1"/>
        <xs:element name="VAT_CODE" type="xs:string" minOccurs="1" maxOccurs="1"/>
    </xs:sequence>
</xs:complexType>

The php call :

$client = new \SoapClient('http://10.55.12.90:18180/NABSCamel/lgg/osp/ws?wsdl', $options);
try {
    $osp = new \stdClass();
    $osp->OSP = new \stdClass();
    $osp->OSP->OSP_ID = $this->meetingRoomBookingI;
    $osp->OSP->DATE_OSP = $date->format('c');
    $osp->OSP->CUSTOMER_ID = $customer->Id();
    $osp->OSP->RECIPIENT_ID = $recipientId;

    $items = [];

    $item = new \stdClass();
    $item->OSP_ITEM = 'test 1';
    $item->VAT_CODE = 21;
    $item->QUANTITY = 2;
    $item->UNIT_PRICE = 3;

    $items[] = $item;

    $item = new \stdClass();
    $item->OSP_ITEM = 'test 2';
    $item->VAT_CODE = 21;
    $item->QUANTITY = 2;
    $item->UNIT_PRICE = 3;

    $items[] = $item;

    $osp->OSP->ITEMS = $items;

    $response = $client->createOspService($osp);
} 
catch (\SoapFault $fault){
    echo $fault->faultstring;
}

I got this error :

SOAP-ERROR: Encoding: object has no 'ITEM' property

I don't find what it's missing something near ITEMS parameter.

ITEMS must be an array with ITEM but where I put this word ITEM in my array ?!

thanks, Phil

If you really don't know how to construct the request and don't want to wonder, then you should definitively use a WSDL to PHP generator that'll generate the associated classes. You won't have to wonder how to construct the request as you'll have each class for each struct. Moreover, the response handling will be easier too.

I suggest you tru the PackageGenerator project which is a good generator.