Hirdetés

Keresés

Új hozzászólás Aktív témák

  • Sk8erPeter

    nagyúr

    válasz j0k3r! #9476 üzenetére

    "ha en asszociativ tombot adok at parameterul, akkor azt struct tipusunak kell definialni a serveren, valamint az indexeket egyesevel meg kell adni neki tipussal egyutt"
    Jaja, persze, a példában, amit korábban linkeltem, szintén ilyen van, ott konkrétan a Stuffs egy struct típus, az id és name elemekkel, és mindez NuSOAP-pal deklarálva a következő:

    $server->wsdl->addComplexType(
    // name
    'Stuffs',
    // typeClass (complexType|simpleType|attribute)
    'complexType',
    // phpType: currently supported are array and struct (php assoc array)
    'struct',
    // compositor (all|sequence|choice)
    'all',
    // restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
    '',
    // elements = array ( name = array(name=>'',type=>'') )
    array(
    'id' => array(
    'name' => 'id',
    'type' => 'xsd:int'
    ),
    'name' => array(
    'name' => 'name',
    'type' => 'xsd:string'
    )
    )
    );

    De mindez még nálam nem volt elég, mert ezeknek a struct-oknak a tömbjét szerettem volna visszaadni (tehát a Stuffs struct-okból álló tömböt, melynek a neve itt StuffsArray):

    $server->wsdl->addComplexType(
    // name
    'StuffsArray',
    // typeClass (complexType|simpleType|attribute)
    'complexType',
    // phpType: currently supported are array and struct (php assoc array)
    'array',
    // compositor (all|sequence|choice)
    '',
    // restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
    'SOAP-ENC:Array',
    // elements = array ( name = array(name=>'',type=>'') )
    array(),
    // attrs
    array(
    array(
    'ref' => 'SOAP-ENC:arrayType',
    'wsdl:arrayType' => 'tns:Stuffs[]'
    )
    ),
    // arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string)
    'tns:Stuffs'
    );

    Aztán még annyival bonyolítottam a dolgot, hogy a kliens kérésére visszaadott válasz szintén egy struct, ami tartalmazza a válaszkódot (responseCode) és a válaszként szánt üzenetet (responseMessage), amivel jelezhető a kommunikáció állapota (pl. hiba vagy épp a siker), ezenkívül tartalmazza az előbb említett StuffsArray-t is, ami hiba esetén NULL, siker esetén az említett struct-ok tömbje.
    Ez kódban így nézett ki:

    $server->wsdl->addComplexType(
    // name
    'ResponseObject',
    // typeClass (complexType|simpleType|attribute)
    'complexType',
    // phpType: currently supported are array and struct (php assoc array)
    'struct',
    // compositor (all|sequence|choice)
    'all',
    // restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array)
    '',
    // elements = array ( name = array(name=>'',type=>'') )
    array
    (
    'responseCode' => array( 'type' => 'xsd:int'),
    'responseMessage' => array( 'type' => 'xsd:string'),
    'stuffArray' => array( 'type' => 'tns:StuffsArray'
    // DON'T UNCOMMENT THE FOLLOWING COMMENTED LINES, BECAUSE THIS WAY IT DOESN'T WORK!!! - Left it in the code not to forget it....
    // ,
    // 'minOccurs' => '0',
    // 'maxOccurs' => 'unbounded'
    )
    )
    );

    Aztán még az ehhez tartozó getStuffs függvény is látható a kódban.
    Elég bonyolult egy ilyen komplex WSDL-t jól legenerálni NuSOAP-pal, de végül is nem lehetetlen (csak jópár óra debuggolás).

Új hozzászólás Aktív témák