Plum Fuse

Sample PHP Webservice Code

« Prev Section VXML Subdialog

The SOAP Webservice module is used to run a SOAP method provided by a WSDL. Parameters can be submitted to this method containing the values of variables in your application. Depending on the return type specified by the WSDL, a value may be saved to the result variable, or rows added to the Stack.

Please note that Plum Fuse supports return types that are simple, e.g., string or integer, or simple objects, or an array of simple objects. Objects with member variables that are also objects are not supported.

For a Plum Fuse tutorial on how to use the SOAP Webservice module, please see the SOAP Integration section.

The 3 source code files given in this tutorial can be used as a reference to assist you in building your own webservice.

NOTE (1/27/11): We now offer a SOAP web service testing tool to allow you to check your web service against. For a link to this SOAP web service tester, please see here.

Sample Webservice Source Code

Download the following archive and extract all three files into some folder within your webroot. Your web server must support PHP, e.g., Apache with mod_php enabled. If you are not sure, contact your server administrator or webhosting service.

Download here: WSDL_Gen.tar.gz

Please note that when using the 3 sample source code files (ws.php, WSDL_Gen.php, and ws_doc.css) below, the only file that you will need to edit is ws.php. Edit the methods within the SampleWebservice class, which will be presented as the methods in your WSDL and accessible via your webservice. You can begin by changing the sample method, testMethod.

In order for the WSDL auto-generation to work properly, each method must be preceded by a docblock, that at a minimum, specifies the type and name for each @param, and the type of the @return value. Docblocks look like this:

   * Method description
   * @param integer $number
   * @param string $text
   * @return string

Once you are ready, access ws.php from whatever URL points your webserver, and it will provide a link to the WSDL that you will supply to Plum Fuse. This link typically ends in ?WSDL.

What follows is our example ws.php file. (You must put the other two files from WSDL_Gen.tar.gz in the same folder for this code to run.)


$WS_DOC_CSS = "ws_doc.css";
$DESCRIPTION = "An example of how to use WSDL_Gen.php";
 * This is a web service class that implements one simple function
 * named testMethod. This function receives one string called $answer
 * and returns a string. If the $answer string is equal to the string, 
 * 'yes', then the function returns the string, "animallover". If the
 * $answer string is not equal to the string, 'no', then the function
 * returns the string, "animalhater".  
class SampleWebservice extends Services_Webservice {
   * @param string $answer
   * @return string
  function testMethod($answer) {
      if ($answer == 'yes'){
        return 'animallover';
    return 'animalhater';
$myService = new SampleWebservice($NAMESPACE, $DESCRIPTION, 
    array('uri'=>$NAMESPACE, 'encoding'=>SOAP_ENCODED));
This is the last section.

Want another tutorial? Learn about Managing Your Apps

tutorial/app_basics/samplewebservice.txt · Last modified: 2014/01/28 14:49 by victor