Multiple registers in server allowed?

Help
2008-10-13
2013-06-06
  • robtcallahan

    robtcallahan - 2008-10-13

    Hi,

    I'm trying to have multiple methods available in my NuSoap web service, but only the first method is recognized. Are multiple registers allowed in NuSoap?

    Rob

     
    • Andre Mamitzsch

      Andre Mamitzsch - 2008-10-13

      yes,it's possible to register multiple functions in your webservice. Pls. post a code snippet, otherwise nobody will be able to help.

       
    • robtcallahan

      robtcallahan - 2008-10-13

      In the following example, I can have the client call getBackupStatsByUser successfully, but when I try
      to call testMethod, I get the following error:
      Fatal error: Uncaught SoapFault exception: [Client] Function ("testMethod") is not a valid method for this service in /home/rtc/tmp/helloworld_client.php:52

      Server Code:
      require_once "DSS.class";
      require_once('nusoap.php');

      // Create the server instance
      $server = new soap_server;
      $server->configureWSDL('BackupService','http://storageweb.ssg.aol.com/webservice/BackupService');
      $server->wsdl->schemaTargetNamespace = 'http://storageweb.ssg.aol.com/webservice/BackupService';
       

      // add complex type
      $server->wsdl->addComplexType(
                                    'UserBackupInfo',
                                    'complexType',
                                    'struct',
                                    'all',
                                    '',
                                    array(
                                          'eligible' => array('name'=>'eligible', 'type'=>'xsd:string'),
                                          'failed' => array('name'=>'failed', 'type'=>'xsd:string'))
                                    );

      // Register the method to expose
      $server->register(
          'getBackupStatsByUser',                  // method name
          array('elementId' => 'xsd:int'),         // input parameters
          array('return' => 'tns:UserBackupInfo'), // output parameters
          'http://storageweb.ssg.aol.com/webservice/BackupService',
          $server->wsdl->endpoint.'#'.'getBackupStatsByUser',
          'rpc',
          'encoded',
          'N/A'
      );

      // Register the method to expose
      $server->register(
          'testMethod',                  // method name
          array('elementId' => 'xsd:int'),         // input parameters
          array('return' => 'xsd:int'), // output parameters
          'http://storageweb.ssg.aol.com/webservice/BackupService',
          $server->wsdl->endpoint.'#'.'testMethod',
          'rpc',
          'encoded',
          'N/A'
      );

      function testMethod($x)
      {
          return $x;
      }

      function getBackupStatsByUser($elementId)
      {
          $eligible = 0;
          $failed = 0;

          $dss = new DSS();
          $hosts = $dss->orb->getCachedHostsByUserElementId($elementId);
         
          $elible = 0;
          $failed = 0;
         
          for ($i=0; $i<count($hosts); $i++)
          {
              $host = $hosts[$i];
              $results = $dss->eba->getLastBackupByElementId($host['element_id']);
              if ($results)
              {
                  $eligible++;
                  if ($results['status'] != "success")
                  {
                      $failed++;
                  }
              }
          }
         
          return array('eligible' => $eligible,
                       'failed' => $failed);
      }

      // Use the request to (try to) invoke the service
      $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
      $server->service($HTTP_RAW_POST_DATA);

       
    • Andre Mamitzsch

      Andre Mamitzsch - 2008-10-14

      you need to change the following line:

      $server = new soap_server;

      to

      $server = new nusoap_server;

      and it should be working.

       
    • robtcallahan

      robtcallahan - 2008-10-14

      I changed the line as you suggested but I'm still getting the same error:
      Function ("testMethod") is not a valid method for this service

      Interesting that it doesn't say that the function cannot be found in the WSDL, it says that it's not valid.

      I'm stumped. I've seen examples like this here:
      http://www.bulahema.com/en/node/136

      I'm using nusoap version 0.7.3.

      Still stumped and stuck,
      Rob

       
    • robtcallahan

      robtcallahan - 2008-10-14

      Solution:

      Had to change the client code to get this to work.
      Was:

      $client = new soapclient('http://storageweb.ssg.aol.com/webservice/BackupService.php?wsdl');
      $results = $proxy->testMethod();

      Fix:

      $client = new nusoap_client('http://storageweb.ssg.aol.com/webservice/BackupService.php?wsdl', "true");
      $proxy = $client->getProxy();
      $results = $proxy->testMethod();

      Don't know why this works, but I'm happy I can now have multiple methods defined and working.

      Thanks for your help,
      Rob

       
    • Andrew Traub

      Andrew Traub - 2009-07-23

      I too cannot seem to get 2 services registered - only the second function shows up when I query the wsdl.  Here is my code:

      $namespace = "xxx";

      // create a new soap server
      $server = new nusoap_server();
      // set our namespace
      $server->wsdl->schemaTargetNamespace = $namespace;

      $param = array('p1' => 'xsd:string','p2' => 'xsd:string','fingerprint' => 'xsd:string');
      $return = array('return'=>'xsd:int');
      // configure our WSDL
      $server->configureWSDL("function1",$namespace);
      // register our WebMethod
      //$server->register('function1',$param,$return,$namespace);
      $server->register(
                      // method name:
                      'function1',         
                      // parameter list:
                      $param,
                      // return value(s):
                      $return,
                      // namespace:
                      $namespace,
                      // soapaction: (use default)
                      false,
                      // style: rpc or document
                      'rpc',
                      // use: encoded or literal
                      'encoded',
                      // description: documentation for the method
                      'xxx');             

      $param = array('p1' => 'xsd:string','p2' => 'xsd:string','p3' => 'xsd:string');
      $return = array('return'=>'xsd:string');
      // configure our WSDL
      $server->configureWSDL("function2",$namespace);
      // register our WebMethod
      //$server->register('function2',$param,$return,$namespace);
      $server->register(
                      // method name:
                      'function2',         
                      // parameter list:
                      $param,
                      // return value(s):
                      $return,
                      // namespace:
                      $namespace,
                      // soapaction: (use default)
                      false,
                      // style: rpc or document
                      'rpc',
                      // use: encoded or literal
                      'encoded',
                      // description: documentation for the method
                      'Register machine id');             
      ...
      functions here
      ...
      // Get our posted data if the service is being consumed
      // otherwise leave this data blank.               
      $POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA'])
                      ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';

      // pass our posted data (or nothing) to the soap service                   
      $server->service($POST_DATA);               
      exit();

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks