Nested input sequences with PHP5 SOAP

Avatar von Björn Schotte

Imagine you have a WebService that defines in its WSDL file the following input structure:

           <xsd:element name="Z_CATSIF_UPDATE_HOURS>
                <xsd:complexType>
                    <xsd:all>
                        [...]
                        <xsd:element name="DATA">
                            <xsd:complexType>
                                <xsd:sequence>
                                    <xsd:element name="item" type="ZCO_CATSIF_COMM" minOccurs="0" maxOccurs="unbounded" />
                                </xsd:sequence>
                            </xsd:complexType>
                        </xsd:element>
               </xsd:complexType>
           </xsd:element>
           <xsd:complexType name="ZCO_CATSIF_COMM">
                <xsd:sequence>
                    <xsd:element name="ELEM1" minOccurs="0">
                        <xsd:simpleType>
                            <xsd:restriction base="xsd:string">
                                <xsd:maxLength value="6" />
                            </xsd:restriction>
                        </xsd:simpleType>
                    </xsd:element>
                    [...]
                </xsd:sequence>
          </xsd:ComplexType>
    <wsdl:message name="rfc.Z_CATSIF_UPDATE_HOURS.Input">
        <wsdl:part name="parameters" element="rfc:Z_CATSIF_UPDATE_HOURS" />
    </wsdl:message>
    <wsdl:message name="rfc.Z_CATSIF_UPDATE_HOURS.Output">
        <wsdl:part name="parameters" element="rfc:Z_CATSIF_UPDATE_HOURS.Response" />
    </wsdl:message>
    <wsdl:portType name="UpdateHours">
        <wsdl:operation name="UpdateHours">
            <wsdl:input message="p1:rfc.Z_CATSIF_UPDATE_HOURS.Input" />
            <wsdl:output message="p1:rfc.Z_CATSIF_UPDATE_HOURS.Output" />
        </wsdl:operation>
    </wsdl:portType>

This is a part of the WSDL definition of an SAP XI web service. As you can see, the WSDL expects the input data in the DATA element which is a folded „item“ sequence containing the complex type ZCO_CATSIF_COMM. So we have a folded structure… in order to have PHP5’s SOAP generate the correct XML code, we use the following:

$obj = new ZCO_CATSIF_COMM($data);

$var = new SoapVar(new item($obj), SOAP_ENC_OBJECT, 'ZCO_CATSIF_COMM', 'urn:sap-com:document:sap:rfc:functions');

$caller_array = array(

  'PROJECT_ID' => $project_id,

  'DATA' => $var

);

$response = $soap_client->UpdateHours($caller_array);

 

So you see that we have two classes which do nothing than creating the corresponding properties that are defined in the WSDL complex types:

class ZCO_CATSIF_COMM {
    public $ELEM1;

    function ZCO_CATSIF_COMM($data) {
      $this->ELEM1 = $data['ELEM1'];
    }
}

class item {
    var $item;

    function item($obj) {
        $this->item = $obj;
    }
}

Right after that, PHP5’s SOAP generates the correct XML code: […]<DATA><item><ELEM1>elem1data</ELEM1></item></DATA>

Goodies von Mayflower

Keine Sorge – Hilfe ist nah! Melde Dich unverbindlich bei uns und wir schauen uns gemeinsam an, ob und wie wir Dich unterstützen können.

Webinar

Avatar von Björn Schotte

Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Für das Handling unseres Newsletters nutzen wir den Dienst HubSpot. Mehr Informationen, insbesondere auch zu Deinem Widerrufsrecht, kannst Du jederzeit unserer Datenschutzerklärung entnehmen.