Document-litteral(return assiciate array)

2011-09-13
2013-06-06
  • Manivasagan
    Manivasagan
    2011-09-13

    Dear Support,

    I am getting documet error in document - litteral style. i have given my code. Please check this and advice me .

    Server side:

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

        // Output Complex Datatype
        $server->wsdl->addComplexType(
                          'TypeDataOutput',
                          'complexType',
                          'struct',
                          'all',
                          '',
                          array(
                                'nim' => array('name' => 'nim', 'type' => 'xsd:int'),
                                'nama' => array('name' => 'nama', 'type' => 'xsd:string'),
                                'alamat' => array('name' => 'alamat', 'type' => 'xsd:string')
                            )
        );

        // Output Array Complex Datatype
        $server->wsdl->addComplexType('TypeDataOutputArray',
                                    'complexType',
                                    'array',
                                    '',
                                    'SOAP-ENC:Array',
                                    array(),
                                    array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:TypeDataOutput')),
                                    'tns:TypeDataOutput'
        );                

    // ## part III - register the methods
    // register the various methods to be called

        // Get Data Mahasiswa
        $server->register('GetDataMahasiswa',        // method name
            array('return' => 'tns:TypeDataInput'),// input parameters
            array('return' => 'tns:TypeDataOutputArray'),        // output parameters
            'urn:ws_multiplearray',                                // namespace
            'urn:ws_multiplearray#GetDataMahasiswa',        // soapaction
            'rpc',                                            // style
            'encoded',                                        // use
            'Get Data Mahasiswa '        // documentation
        );

    // ## part IV - define the functions.
    // finally, define the functions - this can be done in a seperate include file to simplify some of the layout of the file.

        // Define the method as a PHP function
        function GetDataMahasiswa($param)
        {
            // parameter values
            $jurusan = $param ;

            if($jurusan == 'mipa') {
                $loop = 5 ;
            } elseif($jurusan == 'komputer') {
                $loop = 10 ;
            } else {
                $loop = 3 ;
            }

            for ($i = 0; $i <= $loop; $i++) {
                $return = array(
                            'nim' => $i ,
                            'nama' => 'NAMA ke - '.$i ,
                            'alamat' => 'ALAMAT ke - '.$i
                            );
            }

            return $return ;

        }

    Client Side :

    $personArr = array("jurusan"=>"mipa");
    $result = $client->call($call, array('name' => $personArr));

    if ($client->fault) {
        echo '<h2>Fault</h2><pre>';
        print_r($result);
        echo '</pre>';
    }

    Result:

    Array
    (
         => Array
            (
                 => 0
                 => NAMA ke - 0
                 => ALAMAT ke - 0
            )

         => Array
            (
                 => 1
                 => NAMA ke - 1
                 => ALAMAT ke - 1
            )

         => Array
            (
                 => 2
                 => NAMA ke - 2
                 => ALAMAT ke - 2
            )

         => Array
            (
                 => 3
                 => NAMA ke - 3
                 => ALAMAT ke - 3
            )

    )

    But when i change the

    'rpc',        // style
    'encoded',      // use

    to ;

    'document', // style
    'literal', // use

    Result:

    Error

    XML error parsing SOAP payload on line 2: Invalid document end

    Request

    POST /nusoapprogwsdl/wsdlServer.php HTTP/1.0
    Host: localhost
    User-Agent: NuSOAP/0.9.5 (1.123)
    Content-Type: text/xml; charset=ISO-8859-1
    SOAPAction: "http://localhost/nusoapprogwsdl/wsdlServer.php#GetDataMahasiswa"
    Content-Length: 447

    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns8361="http://www.daisy.org/ns/daisy-online/"><SOAP-ENV:Body><GetDataMahasiswa xmlns="urn:Daisy Online Protocol WsdlServer"/></SOAP-ENV:Body></SOAP-ENV:Envelope>

    Response

    HTTP/1.1 200 OK
    Date: Tue, 13 Sep 2011 09:19:49 GMT
    Server: Apache/2.2.19 (Win32) PHP/5.2.8
    X-Powered-By: PHP/5.2.8
    X-SOAP-Server: NuSOAP/0.9.5 (1.123)
    Content-Length: 707
    Connection: close
    Content-Type: text/xml; charset=ISO-8859-1

    <br />
    <b>Warning</b>:  Missing argument 1 for GetDataMahasiswa() in <b>C:\apache\htdocs\nusoapprogwsdl\wsdlServer.php</b> on line <b>183</b><br />
    <br />
    <b>Notice</b>:  Undefined variable: param in <b>C:\apache\htdocs\nusoapprogwsdl\wsdlServer.php</b> on line <b>186</b><br />
    <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><GetDataMahasiswaResponse xmlns="urn:Daisy Online Protocol WsdlServer"></GetDataMahasiswaResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

     
  • Vikq
    Vikq
    2011-10-21

    Hi,

    Can yo u please advice me how to generate ;

    Array
    (
    => Array
    (
    => Chaos Captain
    => array(
    => ‘choas@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas4@sdfusidfousdf.com’,
    ),

    )

    => Array
    (
    => Joe Joe
    => array(
    => ‘choas@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas4@sdfusidfousdf.com’,
    ),
    )

    )

     
  • Vikq
    Vikq
    2011-10-21

    Hi, I am using nuSOAP library and i want response array in below format.

    Can yo u please advice me how to generate it;

    Array
    (
    => Array
    (
    => Chaos Captain
    => array(
    => ‘choas@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas4@sdfusidfousdf.com’,
    ),

    )

    => Array
    (
    => Joe Joe
    => array(
    => ‘choas@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas2@sdfusidfousdf.com’,
    => ‘choas4@sdfusidfousdf.com’,
    ),
    )

    )