public function run() {
        // We will probably need a lot of memory in some functions.
        raise_memory_limit(MEMORY_EXTRA);

        // Set some longer timeout since operations may need longer time to finish.
        external_api::set_timeout();

        // Set up exception handler.
        set_exception_handler(array($this, 'exception_handler'));

        // Init all properties from the request data.
        $this->parse_request();

        // Authenticate user, this has to be done after the request parsing. This also sets up $USER and $SESSION.
        $this->authenticate_user();

        // Make a list of all functions user is allowed to execute.
        $this->init_service_class();

        if ($this->wsdlmode) {
            // Generate the WSDL.
            $this->generate_wsdl();
        }

        // Log the web service request.
        $params = array(
            'other' => array(
                'function' => 'unknown'
            )
        );
        $event = \core\event\webservice_function_called::create($params);
        $logdataparams = array(SITEID, 'webservice_soap', '', '', $this->serviceclass . ' ' . getremoteaddr(), 0, $this->userid);
        $event->set_legacy_logdata($logdataparams);
        $event->trigger();

        // Handle the SOAP request.
        $this->handle();

        // Session cleanup.
        $this->session_cleanup();
        die;
    }