NuSOAP Web service example file

After a few requests I’ve uploaded an example file containing an example web service. This follows most of the guidelines set out in my previous article

Download Zip File

Basically the file splits into 4 parts.

part I – setup

includes the nusoap.php file, sets up the namespace and wsdl object

part II – registering types

registers the types – the singular ones first, then the array types (all using wsdl->addComplexType function)

part III – register the methods

register the various methods to be called using the wsdl->register function.

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. (why oh why did I want to specify part IV first? damn that Star Wars DVD).

See the wsdl in action

As usual, any questions let me know.

9 Replies to “NuSOAP Web service example file”

  1. Hi,

    I’ve started playing with this nusoap example and it looks straightforward except for how a client transmits a binary file (a jpeg file for example) to the FileUpload method.

    It looks like I need to do a file upload on the client (using something lilke HTTP_upload.php) to have the file in hand, then pass this file as a param to the FileUpload method service. This can’t be correct can it? What am I missing here?

    Cheers,
    Douglass Turner
    voice/sms: +354 895 5077

  2. I’m gonna answer this comment with an article on using NuSoap from the client side. However its not something I do myself, I use .Net.

    In .Net you just pass in a byte array (byte[]) as the parameter – but if you consume the WSDL everything is so much easier.

    In PHP you just read the file into a variable (using fread) and then pass that as the parameter to a $client->call() method.

    See this page for a general description of using NuSoap with a wsdl.

  3. I’m wondering if you have an example of a php client comsuming the UploadFile web service. I was playing around with it, and the only way I can get it to work with php client is using base64_encode, and make changes in the web service to use a string instead of the unsignedByte and then using base64_decode. I can’t figure out how to use byte array in php. Some tips would be greatly appreciated.

  4. Hi,

    I am new to nusoap and am trying it out. The query in reality outputs 2 rows. However, only 1 row displays on the client side. I would like to output all the rows. How can I do it?

    I have the following code;

    server
    configureWSDL(‘xmlservice’, ‘urn:schedule’);

    $server->register(“getSchedule”,

    array(‘itemname’ => ‘xsd:string’),
    array(‘return’ => ‘xsd:string’),
    ‘urn:schedule’,
    ‘urn:schedule#getSchedule’);

    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)
    ? $HTTP_RAW_POST_DATA : ”;
    $server->service($HTTP_RAW_POST_DATA);
    ?>

    client
    call(‘getSchedule’,

    array(‘symbol’ => ‘2005-10-02’));

    // I used a static date so that the service returns results

    echo “The info for ‘Friends’ is $info. “;
    print (“”);

    ?>

    Thanks

  5. Hi i have trouble i using PHP 5.0.5 and apache 2, I have error redeclare class soapclient what happen with this??? and how to fix it???

  6. @koko:

    PHP5 has built-in SOAP support, which uses the same classname: soapclient. One way of getting around this is to manually rename the soapclient class name in the nusoap.php source file.

    Another way would be to recompile PHP5 without soap support

  7. Anyone looking at this… for binary file transfer you dont want to use fileBytes.

    all you need to do is send a base64_encoded string back and forth and thats it.

    if($handle = fopen($filename, “r”))
    {
    $data = fread($handle, filesize($filename));

    $data = base64_encode($data);

    fclose($handle);
    return $data;
    }

    return “”;

    … and on the client side… just base64_decode your string… write the data to a file. This is for downloading from a webservice. To upload just do vice versa.

Comments are closed.