function InitTransport($wsdlUrl) { // instantiate wsdl cache manager $cache_use = (bool) Configuration::Instance()->GetValue('application', 'wsdl_use_cache'); $cache_path = file_exists(Configuration::Instance()->GetValue('application', 'wsdl_cache_path')) ? Configuration::Instance()->GetValue('application', 'wsdl_cache_path') : Configuration::Instance()->GetValue('application', 'session_save_path'); // paranoia check, if session_save_path set to NULL $cache_path = file_exists($cache_path) ? $cache_path : ini_get('session.save_path'); // $cache_lifetime = Configuration::Instance()->GetValue('application', 'wsdl_cache_lifetime') != '' ? (int) Configuration::Instance()->GetValue('application', 'wsdl_cache_lifetime') : 60 * 60 * 24; // defaults to 1 day if ($cache_path != '' && $cache_use) { $wsdl_cache = new wsdlcache($cache_path, $cache_lifetime); } // try to get from cache first... if ($wsdl_cache) { $wsdl = $wsdl_cache->get($wsdlUrl); } // cache hit? if not, get it from server and put to cache if (!$wsdl) { $wsdl = new wsdl($wsdlUrl, $this->mProxyHost, $this->mProxyPort, $this->mProxyUser, $this->mProxyPass); if ($wsdl_cache && !$wsdl->getError()) { $wsdl_cache->put($wsdl); } } $this->mTransport = new soapclient($wsdl, TRUE, $this->mProxyHost, $this->mProxyPort, $this->mProxyUser, $this->mProxyPass); }
public function Connect() { // instantiate wsdl cache manager if ($this->mDbConfig['db_wsdl_cache_path'] != '' && $this->mDbConfig['db_wsdl_cache_enabled']) { $wsdl_cache = new wsdlcache($this->mDbConfig['db_wsdl_cache_path'], $this->mDbConfig['db_wsdl_cache_lifetime']); } // try to get from cache first... $wsdl_url = $this->mDbConfig['db_wsdl_url']; if ($this->mDbConfig['db_namespace']) { $wsdl_url_query = parse_url($wsdl_url, PHP_URL_QUERY); if (!$wsdl_url_query) { $wsdl_url .= '?nspace=' . $this->mDbConfig['db_namespace']; } else { $wsdl_url .= '&nspace=' . $this->mDbConfig['db_namespace']; } } if ($wsdl_cache) { $wsdl = $wsdl_cache->get($wsdl_url); } // cache hit? if not, get it from server and put to cache if (!$wsdl) { SysLog::Log('Cache MISSED: ' . $wsdl_url, 'SoapDatabaseEngine'); $wsdl = new wsdl($wsdl_url, $this->mDbConfig['db_proxy_host'], $this->mDbConfig['db_proxy_port'], $this->mDbConfig['db_proxy_user'], $this->mDbConfig['db_proxy_pass'], $this->mDbConfig['db_connection_timeout'], $this->mDbConfig['db_response_timeout']); $this->mErrorMessage = $wsdl->getError(); if ($this->mErrorMessage) { SysLog::Log('WSDL error: ' . $this->mErrorMessage, 'DatabaseEngine'); $this->mErrorMessage = 'An error has occured when instantiating WSDL object (' . $this->mDbConfig['db_wsdl_url'] . '&nspace=' . $this->mDbConfig['db_namespace'] . '). The error was: "' . $this->mErrorMessage . '" Check your WSDL document or database configuration.'; return FALSE; } if ($wsdl_cache) { $wsdl_cache->put($wsdl); } } else { SysLog::Log('Cache HIT: ' . $this->mDbConfig['db_wsdl_url'] . '&nspace=' . $this->mDbConfig['db_namespace'], 'SoapDatabaseEngine'); } // use it as usual $temp = new soapclient($wsdl, TRUE, $this->mDbConfig['db_proxy_host'], $this->mDbConfig['db_proxy_port'], $this->mDbConfig['db_proxy_user'], $this->mDbConfig['db_proxy_pass'], $this->mDbConfig['db_connection_timeout'], $this->mDbConfig['db_response_timeout']); $this->mErrorMessage = $temp->getError(); if (!$this->mErrorMessage) { $this->mrDbConnection = $temp->getProxy(); if (isset($this->mDbConfig['db_credentials'])) { $this->mrDbConnection->setCredentials($this->mDbConfig['db_credentials']['user'], $this->mDbConfig['db_credentials']['pass'], $this->mDbConfig['db_credentials']['type'], $this->mDbConfig['db_credentials']['cert']); } return TRUE; } else { SysLog::Log('Error in SoapDatabaseEngine: ' . $temp->getError(), 'SoapDatabaseEngine'); return FALSE; } }
* Payload: rpc/encoded * Transport: http * Authentication: none */ require_once '../lib/nusoap.php'; require_once '../lib/class.wsdlcache.php'; $proxyHost = isset($_POST['proxyHost']) ? $_POST['proxyHost'] : ''; $proxyPort = isset($_POST['proxyPort']) ? $_POST['proxyPort'] : ''; $proxyUsername = isset($_POST['proxyUsername']) ? $_POST['proxyUsername'] : ''; $proxyPassword = isset($_POST['proxyPassword']) ? $_POST['proxyPassword'] : ''; $useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0'; $cache = new wsdlcache('.', 60); $wsdl = $cache->get('http://www.xmethods.net/sd/2001/BNQuoteService.wsdl'); if (is_null($wsdl)) { $wsdl = new wsdl('http://www.xmethods.net/sd/2001/BNQuoteService.wsdl', $proxyHost, $proxyPort, $proxyUsername, $proxyPassword, 0, 30, null, $useCURL); $err = $wsdl->getError(); if ($err) { echo '<h2>WSDL Constructor error (Expect - 404 Not Found)</h2><pre>' . $err . '</pre>'; echo '<h2>Debug</h2><pre>' . htmlspecialchars($wsdl->getDebug(), ENT_QUOTES) . '</pre>'; exit; } $cache->put($wsdl); } else { $wsdl->clearDebug(); $wsdl->debug('Retrieved from cache'); } $client = new nusoap_client($wsdl, 'wsdl', $proxyHost, $proxyPort, $proxyUsername, $proxyPassword); $err = $client->getError(); if ($err) { echo '<h2>Constructor error</h2><pre>' . $err . '</pre>'; exit;
private function RegisterServiceByWsdlConfig($wsdlConfig = NULL) { if (!$wsdlConfig) { return FALSE; } if ($wsdlConfig['location'] == 'remote') { if ($this->mUseWsdlCache) { $wsdl_cache = new wsdlcache($this->mWsdlCachePath, $this->mWsdlCacheLifetime); } // try to get from cache first... if ($wsdl_cache) { $wsdl = $wsdl_cache->get($wsdlConfig['address']); } // cache hit? if not, get it from server and put to cache if (!$wsdl) { $wsdl = new wsdl($wsdlConfig['address'], $wsdlConfig['proxy_host'], $wsdlConfig['proxy_port'], $wsdlConfig['proxy_user'], $wsdlConfig['proxy_pass']); $error = $wsdl->getError(); if ($error) { SysLog::Log('An error occured when fecthing wsdl from ' . $wsdlConfig['address'] . ': ' . $error, 'wsdlgenerator'); } if ($wsdl_cache && !$error) { $wsdl_cache->put($wsdl); } } if (!$error) { $this->RegisterServiceByWsdlObject($wsdl); } } elseif ($wsdlConfig['location'] == 'local') { $this->RegisterServiceBySoapClass($wsdlConfig); } }
protected function importWsdlUrl($wsdl_url, $proxy_host = '', $proxy_port = '', $proxy_user = '', $proxy_pass = '') { SysLog::Instance()->log("importing from {$wsdl_url}", 'soapgateway'); // instantiate wsdl cache manager $cache_use = (bool) Configuration::Instance()->GetValue('application', 'wsdl_use_cache'); $cache_path = file_exists(Configuration::Instance()->GetValue('application', 'wsdl_cache_path')) ? Configuration::Instance()->GetValue('application', 'wsdl_cache_path') : Configuration::Instance()->GetTempDir(); $cache_lifetime = Configuration::Instance()->GetValue('application', 'wsdl_cache_lifetime') != '' ? (int) Configuration::Instance()->GetValue('application', 'wsdl_cache_lifetime') : 60 * 60 * 24; // defaults to 1 day if ($cache_path != '' && $cache_use) { $wsdl_cache = new wsdlcache($cache_path, $cache_lifetime); } // try to get from cache first... if ($wsdl_cache) { $wsdl = $wsdl_cache->get($wsdl_url); } // cache hit? if not, get it from server and put to cache if (!$wsdl) { $wsdl = new wsdl($wsdl_url, $proxy_host, $proxy_port, $proxy_user, $proxy_pass); if ($wsdl_cache && !$wsdl->getError()) { $wsdl_cache->put($wsdl); } } if (is_object($wsdl) && !$wsdl->getError()) { // adjustment: re-encode URL, since after importing somewhoe it won't be escaped anymore thus yields in invalid xml if (count($wsdl->ports) >= 1) { foreach ($wsdl->ports as $pName => $attrs) { if (preg_match('/(.*)?\\?(.*)/', $attrs['location'], $found)) { $main_url = $found[1]; $query_str = $found[2]; if (!empty($query_str)) { $main_url .= '?'; } } else { $main_url = $attrs; $query_str = ''; } $wsdl->ports["{$pName}"]['location'] = $main_url . htmlentities($query_str); } } $this->importWsdlObject($wsdl); } else { SysLog::Instance()->log("Unable to read wsdl from url: {$wsdl_url}", 'soapgateway'); } }
/** * Internal utility methods */ private function call($service, $method, $params) { ini_set('memory_limit', '1024M'); ini_set('max_execution_time', 1800); set_time_limit(0); $url = $this->wsdl_root . $service . '.asmx?wsdl'; $timeout = 3000; $cache = new nusoap_wsdlcache($this->cache_dir, $timeout); $wsdl = $cache->get($url); // Set the WSDL if (is_null($wsdl)) { $wsdl = new wsdl($url, NULL, NULL, NULL, NULL, 0, $timeout, NULL, TRUE); $error = $wsdl->getError(); $debug = $wsdl->getDebug(); $wsdl->clearDebug(); // Check for SOAP errors if (!empty($error)) { $this->errors[] = $error; if ($debug) { $this->errors[] = '<pre>' . print_r($debug, TRUE) . '</pre>'; } return FALSE; } $cache->put($wsdl); } // Send the SOAP request $params['securityPassword'] = $this->wsdl_keys[$service]; $client = new nusoap_client($wsdl, 'wsdl', FALSE, FALSE, FALSE, FALSE, 0, $timeout); $client->setDebugLevel(0); // 0 - 9, where 0 is off $client->useHTTPPersistentConnection(); if ($service == 'DataAccess' && $method == 'ExecuteStoredProcedure') { /* * See http://www.codingforums.com/archive/index.php/t-85260.html * and http://users.skynet.be/pascalbotte/rcx-ws-doc/nusoapadvanced.htm * for how to thwart the "got wsdl error: phpType is struct, but value is not an array" * error returned by nusoap when processing the response from $client->call() * * */ $request = $client->serializeEnvelope(vsprintf('<ExecuteStoredProcedure xmlns="http://ibridge.isgsolutions.com/%s/"> <securityPassword>%s</securityPassword> <name>%s</name> <parameters>%s</parameters> </ExecuteStoredProcedure>', array($service, $params['securityPassword'], $params['name'], $params['parameters']))); $response = $client->send($request, 'http://ibridge.isgsolutions.com/' . $service . '/' . $method, 0, $timeout); } else { $response = $client->call($method, $params); } $error = $client->getError(); $debug = $client->getDebug(); $client->clearDebug(); // Check for SOAP errors if (!empty($error)) { $this->errors[] = $error; if ($debug) { $this->errors[] = '<pre>' . print_r($debug, TRUE) . '</pre>'; } return FALSE; } // Process response $response = $response[$method . 'Result']; $data = NULL; if (strpos($response, '<') == 0) { // Some ISGweb methods return strings instead of XML libxml_use_internal_errors(TRUE); $response = preg_replace('/(<\\?xml[^?]+?)utf-16/i', '$1utf-8', $response); // Change encoding string to UTF8 $response = utf8_encode($response); $response = $this->strip_invalid_xml($response); $obj = simplexml_load_string($response); $data = $response; $error = libxml_get_errors(); // Check for XML parsing errors if (!empty($error)) { foreach ($error as $e) { $this->errors[] = $e; } libxml_clear_errors(); return FALSE; } $data = $this->object_to_array($obj); // Check for ISGweb errors (e.g. invalid data input, failure of service, etc.) if (array_key_exists('Errors', $data)) { $error = $data['Errors']; foreach ($error as $e) { $this->errors[] = $e['@attributes']['Description']; } return FALSE; } } else { $data = $response; } return $data; }