Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-49560

SOAP web service does not work with token

    XMLWordPrintable

Details

    Description

      Test on moodle 2.8.5+

      Tried to use web services protocol SOAP.
      Configure moodle web service as described in the documentation (https://docs.moodle.org/28/en/Using_web_services).
      Created a web service client, as shown here: https://docs.moodle.org/dev/Creating_a_web_service_client

      WSDL was not created automatically, SoapClient generated an error:
      Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://localhost/moodle/webservice/soap/server.php?wsdl=1&wstoken=af881bc315aae584f8f20f106b5d4075' : failed to load external entity "http://localhost/moodle/webservice/soap/server.php?wsdl=1&wstoken=af881bc315aae584f8f20f106b5d4075" in D:\server\home\localhost\www\index.php on line 73

      After this I change value NO_DEBUG_DISPLAY to false (/webservice/soap/server.php on line 29). Script gave me an error:
      Fatal error: Cannot redeclare class webservices_struct_class_000027 in D:\server\home\moodle.pgtu\www\webservice\soap\locallib.php(300) : eval()'d code on line 5

      This error occurs due to the use of recursion in the file /webservice/soap/locallib.php on line 285 and calls method get_phpdoc_type($fieldsdesc). Incremented previously webservices_struct_class_000000 class name is overwritten with a new value as a result of calling this method, and when you try to create a new class with the same name, the script gives an error.

      To get rid of this error, you need to swap the check for the generated class and calling get_phpdoc_type

      New code of method:
      /**

      • Generate 'struct' type name
      • This type name is the name of a class generated on the fly.
        *
      • @param external_single_structure $structdesc
      • @return string
        */
        protected function generate_simple_struct_class(external_single_structure $structdesc) {
        global $USER;

      $fields = array();
      foreach ($structdesc->keys as $name => $fieldsdesc)

      { $type = $this->get_phpdoc_type($fieldsdesc); $fields[] = ' /** @var '.$type." */\n" . ' public $'.$name.';'; }

      // let's use unique class name, there might be problem in unit tests
      $classname = 'webservices_struct_class_000000';
      while(class_exists($classname))

      { $classname++; }

      $code = '
      /**

      • Virtual struct class for web services for user id '.$USER->id.' in context '.$this->restricted_context->id.'.
        */
        class '.$classname.' { '.implode("\n", $fields).' }

        ';
        eval($code);
        return $classname;
        }

      Attachments

        Activity

          People

            moodle.com Moodle HQ
            el_lenidych El Leonidych
            Dave Cooper Dave Cooper
            Dan Poltawski Dan Poltawski
            Rajesh Taneja Rajesh Taneja
            Juan Leyva, David Woloszyn, Huong Nguyen, Jake Dallimore, Meirza, Michael Hawkins, Raquel Ortega, Safat Shahin, Stevani Andolo
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              6/Jul/15