/** * Finally returns a SoapClient instance. * * @return \BeSimple\SoapServer\SoapServer */ public function build() { $this->validateOptions(); use_soap_error_handler($this->errorReporting); $server = new SoapServer($this->wsdl, $this->getSoapOptions()); if (null !== $this->persistence) { $server->setPersistence($this->persistence); } if (null !== $this->handlerClass) { $server->setClass($this->handlerClass); } elseif (null !== $this->handlerObject) { $server->setObject($this->handlerObject); } return $server; }
/** * Get SoapServer object * * Uses {@link $_wsdl} and return value of {@link getOptions()} to instantiate * SoapServer object, and then registers any functions or class with it, as * well as peristence. * * @return SoapServer */ protected function _getSoap() { $options = $this->getOptions(); $server = new SoapServer($this->_wsdl, $options); if (!empty($this->_functions)) { $server->addFunction($this->_functions); } if (!empty($this->_class)) { $args = $this->_classArgs; array_unshift($args, $this->_class); call_user_func_array(array($server, 'setClass'), $args); } if (!empty($this->_object)) { $server->setObject($this->_object); } if (null !== $this->_persistence) { $server->setPersistence($this->_persistence); } return $server; }
/** * Handles the web service request. */ public function run() { header('Content-Type: text/xml;charset=' . $this->encoding); if (YII_DEBUG) { ini_set("soap.wsdl_cache_enabled", 0); } $server = new SoapServer($this->wsdlUrl, $this->getOptions()); Yii::app()->attachEventHandler('onError', array($this, 'handleError')); try { if ($this->persistence !== null) { $server->setPersistence($this->persistence); } if (is_string($this->provider)) { $provider = Yii::createComponent($this->provider); } else { $provider = $this->provider; } if (method_exists($server, 'setObject')) { if (is_array($this->generatorConfig) && isset($this->generatorConfig['bindingStyle']) && $this->generatorConfig['bindingStyle'] === 'document') { $server->setObject(new CDocumentSoapObjectWrapper($provider)); } else { $server->setObject($provider); } } else { if (is_array($this->generatorConfig) && isset($this->generatorConfig['bindingStyle']) && $this->generatorConfig['bindingStyle'] === 'document') { $server->setClass('CDocumentSoapObjectWrapper', $provider); } else { $server->setClass('CSoapObjectWrapper', $provider); } } if ($provider instanceof IWebServiceProvider) { if ($provider->beforeWebMethod($this)) { $server->handle(); $provider->afterWebMethod($this); } } else { $server->handle(); } } catch (Exception $e) { if ($e->getCode() !== self::SOAP_ERROR) { // only log for non-PHP-error case because application's error handler already logs it // php <5.2 doesn't support string conversion auto-magically Yii::log($e->__toString(), CLogger::LEVEL_ERROR, 'application'); } $message = $e->getMessage(); if (YII_DEBUG) { $message .= ' (' . $e->getFile() . ':' . $e->getLine() . ")\n" . $e->getTraceAsString(); } // We need to end application explicitly because of // http://bugs.php.net/bug.php?id=49513 Yii::app()->onEndRequest(new CEvent($this)); $server->fault(get_class($e), $message); exit(1); } }
//for checking the connection public function check_connection($data) { if ($this->valid($data[0])) { return 'ok'; } else { return 'notok'; } } /** * Checks whether a module is installed or not * @param type $parameter_array * @return type */ public function checkModuleInstalled($parameter_array = array()) { if ($this->valid($parameter_array[0])) { $module_name = isset($parameter_array[1]) ? $parameter_array[1] : ''; $sql = "SELECT mod_id FROM modules WHERE mod_name = ? AND mod_active = '1'"; $res = sqlStatement($sql, array($module_name)); $row = sqlFetchArray($res); return !empty($row); } else { return 'noauth'; } } } $server = new SoapServer(null, array('uri' => "urn://portal/res")); $server->setClass('UserService'); $server->setPersistence(SOAP_PERSISTENCE_SESSION); $server->handle();
/** * Get SoapServer object * * Uses {@link $_wsdl} and return value of {@link getOptions()} to instantiate * SoapServer object, and then registers any functions or class with it, as * well as peristence. * * @return SoapServer */ protected function _getSoap() { $options = $this->getOptions(); $server = new SoapServer($this->_wsdl, $options); if (!empty($this->_functions)) { $server->addFunction($this->_functions); } if (!empty($this->_class)) { $args = $this->_classArgs; array_unshift($args, $this->_class); if ($this->_wsiCompliant) { #require_once 'Zend/Soap/Server/Proxy.php'; array_unshift($args, 'Zend_Soap_Server_Proxy'); } call_user_func_array(array($server, 'setClass'), $args); } if (!empty($this->_object)) { $server->setObject($this->_object); } if (null !== $this->_persistence) { $server->setPersistence($this->_persistence); } return $server; }
/** * Handles the web service request. */ public function run() { $response = \Yii::$app->response; $response->format = Response::FORMAT_RAW; $response->charset = $this->encoding; $response->headers->add('Content-Type', 'text/xml'); if (YII_DEBUG) { ini_set("soap.wsdl_cache_enabled", 0); } $server = new \SoapServer($this->wsdlUrl, $this->getOptions()); // \Yii::$app->on($name, $behavior)EventHandler('onError',array($this,'handleError')); try { if ($this->persistence !== null) { $server->setPersistence($this->persistence); } if (is_string($this->provider)) { $provider = \Yii::createObject($this->provider); } else { $provider = $this->provider; } if (method_exists($server, 'setObject')) { if (is_array($this->generatorConfig) && isset($this->generatorConfig['bindingStyle']) && $this->generatorConfig['bindingStyle'] === 'document') { $server->setObject(new DocumentSoapObjectWrapper($provider)); } else { $server->setObject($provider); } } else { if (is_array($this->generatorConfig) && isset($this->generatorConfig['bindingStyle']) && $this->generatorConfig['bindingStyle'] === 'document') { $server->setClass(DocumentSoapObjectWrapper::className(), $provider); } else { $server->setClass(SoapObjectWrapper::className(), $provider); } } if ($provider instanceof IWebServiceProvider) { if ($provider->beforeWebMethod($this)) { $server->handle(); $provider->afterWebMethod($this); } } else { $server->handle(); } } catch (\Exception $e) { if ($e->getCode() !== self::SOAP_ERROR) { // only log for non-PHP-error case because application's error handler already logs it // php <5.2 doesn't support string conversion auto-magically \Yii::error($e->__toString()); } $message = $e->getMessage(); if (YII_DEBUG) { $message .= ' (' . $e->getFile() . ':' . $e->getLine() . ")\n" . $e->getTraceAsString(); } // We need to end application explicitly because of // http://bugs.php.net/bug.php?id=49513 \Yii::$app->state = Application::STATE_AFTER_REQUEST; \Yii::$app->trigger(Application::EVENT_AFTER_REQUEST); $reflect = new \ReflectionClass($e); $server->fault($reflect->getShortName(), $message); exit(1); } }
$url = "https://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]; $delay = 1; die('<meta http-equiv="refresh" content="' . $delay . ';url=' . $url . '">'); } include_once "moodleplugin.php"; ini_set('soap.wsdl_cache_enabled', 0); $server = new SoapServer("moodleplugin.wsdl", array('soap_version' => SOAP_1_2, 'encoding' => "UTF-8")); $server->setClass("MoodlePlugin"); session_start(); session_name('PHPMOODLEWSSESSID'); /*if (!(adminlogin($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW']))) { // Check username and password authenticate(); // Send basic authentication headers because username and/or password didnot match } else {*/ if ($_SERVER["REQUEST_METHOD"] == "POST") { $server->setPersistence(SOAP_PERSISTENCE_REQUEST); try { $server->handle(); } catch (Exception $exc) { $server->fault($exc->getCode(), $exc->getMessage()); } } else { #output function list of webserver $functions = $server->getFunctions(); foreach ($functions as $func) { echo $func . "<br>"; } } //} // Call authentication display function authenticate()
/** * Handles the web service request. */ public function run() { header('Content-Type: text/xml;charset=' . $this->encoding); if (YII_DEBUG) { ini_set("soap.wsdl_cache_enabled", 0); } $server = new SoapServer($this->wsdlUrl, $this->getOptions()); Yii::app()->attachEventHandler('onError', array($this, 'handleError')); try { if ($this->persistence !== null) { $server->setPersistence($this->persistence); } if (is_string($this->provider)) { $provider = Yii::createComponent($this->provider); } else { $provider = $this->provider; } if (method_exists($server, 'setObject')) { $server->setObject($provider); } else { $server->setClass('CSoapObjectWrapper', $provider); } if ($provider instanceof IWebServiceProvider) { if ($provider->beforeWebMethod($this)) { $server->handle(); $provider->afterWebMethod($this); } } else { $server->handle(); } } catch (Exception $e) { if ($e->getCode() === self::SOAP_ERROR) { // a PHP error $message = $e->getMessage(); } else { $message = $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ')'; // only log for non-PHP-error case because application's error handler already logs it // php <5.2 doesn't support string conversion auto-magically Yii::log($e->__toString(), CLogger::LEVEL_ERROR, 'application'); } if (YII_DEBUG) { $message .= "\n" . $e->getTraceAsString(); } $server->fault(get_class($e), $message); } }
/** * Run the PHP SoapServer * * @param string $wsdlFile The WSDL file name or NULL to let PhpWsdl decide (default: NULL) * @param string|object|array $class The class name to serve, the classname and class as array or NULL (default: NULL) * @param boolean $andExit Exit after running the server? (default: TRUE) * @param boolean $forceNoWsdl Force no WSDL usage? (default: FALSE); * @return boolean Did the server run? */ public function RunServer($wsdlFile = null, $class = null, $andExit = true, $forceNoWsdl = false) { self::Debug('Run the server'); if ($forceNoWsdl) { self::Debug('Forced non-WSDL mode'); } if (self::CallHook('BeforeRunServerHook', array('server' => $this, 'wsdlfile' => &$wsdlFile, 'class' => &$class, 'andexit' => &$andExit, 'forcenowsdl' => &$forceNoWsdl))) { // WSDL requested? if ($this->OutputWsdlOnRequest($andExit)) { return false; } // PHP requested? if ($this->OutputPhpOnRequest($andExit)) { return false; } // HTML requested? if ($this->OutputHtmlOnRequest($andExit)) { return false; } } // Login $user = null; $password = null; if ($this->RequireLogin) { if (isset($_SERVER['PHP_AUTH_USER']) || isset($_SERVER['PHP_AUTH_PW'])) { $user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : null; $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null; } self::Debug('Check login ' . $user . ':' . str_repeat('*', strlen($password))); if (!self::CallHook('LoginHook', array('server' => $this, 'user' => &$user, 'password' => &$password))) { self::Debug('Login required'); header('WWW-Authenticate: Basic realm="Webservice login required"'); header('HTTP/1.0 401 Unauthorized'); if ($andExit) { self::Debug('Exit script execution'); exit; } return false; } } // Load the proxy $useProxy = false; if (is_array($class)) { self::Debug('Use the proxy for ' . $class[0]); self::$ProxyObject = $class[1]; self::$ProxyServer = $this; $class = $class[0]; $useProxy = true; } // Ensure a webservice name if (is_null($class)) { self::Debug('No webservice name yet'); if (!$this->DetermineConfiguration()) { throw new Exception('Invalid configuration'); } if (!is_null($this->Name)) { $class = $this->Name; } } else { if (is_string($class)) { self::Debug('Using ' . $class . ' as webservice name'); $this->Name = $class; } } self::Debug('Use class ' . (!is_object($class) ? $class : get_class($class))); // Load WSDL if (!$forceNoWsdl && (!$useProxy || self::$UseProxyWsdl)) { self::Debug('Load WSDL'); $this->CreateWsdl(false, true); if (is_null($wsdlFile)) { $wsdlFile = $this->GetCacheFileName(); } if (!is_null($wsdlFile)) { if (!file_exists($wsdlFile)) { self::Debug('WSDL file "' . $wsdlFile . '" does not exists'); $wsdlFile = null; } } } // Load the files, if the webservice handler class doesn't exist if (!is_object($class)) { if (!class_exists($class) && !$this->IsOnlyGlobal()) { self::Debug('Try to load the webservice handler class'); $i = -1; $len = sizeof($this->Files); while (++$i < $len) { self::Debug('Load ' . $this->Files[$i]); require_once $this->Files[$i]; } if (!class_exists($class)) { // Try class.webservice.php if (file_exists('class.webservice.php')) { self::Debug('Try to load class.webservice.php'); require_once 'class.webservice.php'; if (class_exists($class)) { $this->Files[] = 'class.webservice.php'; } } if (!class_exists($class)) { if (file_exists(dirname(__FILE__) . '/class.webservice.php')) { self::Debug('Try to load ' . dirname(__FILE__) . '/class.webservice.php'); require_once dirname(__FILE__) . '/class.webservice.php'; if (class_exists($class)) { $this->Files[] = dirname(__FILE__) . '/class.webservice.php'; } } } if (!class_exists($class)) { // A handler class or object is required when using non-global methods! throw new Exception('Webservice handler class not present'); } } } } // Prepare the PhpWsdlHandler if ($this->CreateHandler) { self::Debug('Use PhpWsdlHandler'); if (is_null($class)) { $class = $this->Name; } $class = $this->CreateHandler($class); } // Prepare the SOAP server $this->SoapServer = null; if (self::CallHook('PrepareServerHook', array('server' => $this, 'soapserver' => &$this->SoapServer, 'wsdlfile' => &$wsdlFile, 'class' => &$class, 'useproxy' => &$useProxy, 'forcenowsdl' => &$forceNoWsdl, 'andexit' => &$andExit, 'user' => &$user, 'password' => &$password))) { self::Debug('Prepare the SOAP server'); // WSDL file $wsdlFile = $forceNoWsdl || $useProxy && !self::$UseProxyWsdl ? null : $wsdlFile; if (!is_null($wsdlFile)) { self::Debug('Using WSDL file ' . $wsdlFile); } else { self::Debug('No WSDL file'); } // Server options $temp = array('actor' => $this->EndPoint, 'uri' => $this->NameSpace); $temp = array_merge($this->SoapServerOptions, $temp); if (self::$Debugging) { self::Debug('Server options: ' . print_r($temp, true)); } // Create the server object self::Debug('Creating PHP SoapServer object'); $this->SoapServer = new SoapServer($wsdlFile, $temp); // Set the handler class or object if ($useProxy || !is_object($class)) { $temp = $useProxy ? 'PhpWsdlProxy' : $class; if (!is_null($temp)) { self::Debug('Setting server class ' . $temp); $this->SoapServer->setClass($temp); } else { self::Debug('No server class or object'); } } else { self::Debug('Setting server object ' . get_class($class)); $this->SoapServer->setObject($class); } // Add global methods if (!$useProxy && !$this->CreateHandler) { $i = -1; $len = sizeof($this->Methods); while (++$i < $len) { if ($this->Methods[$i]->IsGlobal) { self::Debug('Adding global method ' . $this->Methods[$i]->Name); $this->SoapServer->addFunction($this->Methods[$i]->Name); } } } else { self::Debug('Omit adding global methods to the SoapServer object since they will be called by the proxy or the PhpWsdlHandler object'); } } // Run the SOAP server if (self::CallHook('RunServerHook', array('server' => $this, 'soapserver' => &$this->SoapServer, 'wsdlfile' => &$wsdlFile, 'class' => &$class, 'useproxy' => &$useProxy, 'forcenowsdl' => &$forceNoWsdl, 'andexit' => &$andExit, 'user' => &$user, 'password' => &$password))) { self::Debug('Run the SOAP server'); //Ignatyev begin $this->SoapServer->setPersistence(SOAP_PERSISTENCE_SESSION); //Ignatyev end $this->SoapServer->handle(); if ($andExit) { self::Debug('Exit script execution'); exit; } } return true; }
/** * Handles the web service request. */ public function run() { header('Content-Type: text/xml;charset=' . $this->encoding); if (YII_DEBUG) { ini_set("soap.wsdl_cache_enabled", 0); } list(, $hash) = explode(' ', \Yii::$app->getRequest()->getHeaders()->get('authorization') . ' '); $auth = $hash ? base64_decode($hash) . '@' : ''; $server = new \SoapServer(str_replace('http://', 'http://' . $auth, $this->wsdlUrl), $this->getOptions()); try { if ($this->persistence !== null) { $server->setPersistence($this->persistence); } if (is_string($this->provider)) { $provider = $this->provider; $provider = new $provider(); } else { $provider = $this->provider; } $server->setObject($provider); ob_start(); $server->handle(); $soapXml = ob_get_contents(); ob_end_clean(); return $soapXml; } catch (Exception $e) { if ($e->getCode() !== self::SOAP_ERROR) { // only log for non-PHP-error case because application's error handler already logs it // php <5.2 doesn't support string conversion auto-magically \Yii::error($e->__toString()); } $message = $e->getMessage(); if (YII_DEBUG) { $message .= ' (' . $e->getFile() . ':' . $e->getLine() . ")\n" . $e->getTraceAsString(); } // We need to end application explicitly because of // http://bugs.php.net/bug.php?id=49513 $server->fault(get_class($e), $message); exit(1); } }
<?php require_once 'Ahorcado.class.php'; function autoinclude($className) { $className = str_replace('\\', '/', $className) . '.php'; require_once $className; } spl_autoload_register('autoinclude'); if (isset($_GET['wsdl'])) { header('Content-Type: application/soap+xml; charset=utf-8'); echo file_get_contents('Ahorcado.wsdl'); } else { session_start(); if (!isset($_SESSION['service'])) { $_SESSION['service'] = new Ahorcado(); } $servidorSoap = new SoapServer('C:\\Users\\Iva\\Documents\\II-2015\\Apps\\TareaWebService\\TPRepo\\Ahorcado.wsdl'); //poner la ruta en tu compu //Para evitar la excepción por defecto de SOAP PHP cuando no existe HTTP_RAW_POST_DATA, //se regresa explícitamente el siguiente fallo cuando no hay solicitud (v.b. desde un navegador) if (!@$HTTP_RAW_POST_DATA) { $servidorSoap->fault('SOAP-ENV:Client', 'Invalid Request'); exit; } $servidorSoap->setObject(new Zend\Soap\Server\DocumentLiteralWrapper($_SESSION['service'])); $servidorSoap->setPersistence(SOAP_PERSISTENCE_SESSION); $servidorSoap->handle(); }