Пример #1
0
 public function __construct($url, $username, $password, $timeout = 3600, $response_timeout = 3600)
 {
     $this->username = $username;
     $this->password = $password;
     $this->url = $url;
     $this->result_object = new ResultObject();
     // Caching the WSDL
     $cache = new nusoap_wsdlcache('.', 300);
     $wsdl = $cache->get($url);
     if (is_null($wsdl)) {
         $wsdl = new wsdl($url, '', '', '', '', 5);
         $cache->put($wsdl);
     }
     $this->client = new nusoap_client($wsdl, $this->service_type, false, false, false, false, $timeout, $response_timeout, '');
     if (!is_null($username) && !is_null($password)) {
         $this->client->setHeaders($this->getRequestHeader($this->username, $this->password));
     }
     $err = $this->client->getError();
     if ($err) {
         echo '<h2>Constructor error</h2> <pre>' . $err . '</pre>';
     }
 }
Пример #2
0
 protected function getClient()
 {
     if (!isset($this->client) || !$this->client) {
         nusoap_base::setGlobalDebugLevel(0);
         $wsdl_path = $this->getWSDLLocation();
         $cache = new nusoap_wsdlcache('/tmp', 86400);
         $wsdl = $cache->get($url);
         if (is_null($wsdl)) {
             $wsdl = new wsdl($wsdl_path, '', '', '', '', 5);
             $cache->put($wsdl);
         }
         $client = new nusoap_client($wsdl, 'wsdl');
         //$client = new nusoap_client($wsdl_path, true);
         $client->decode_utf8 = false;
         //$client->setDebugLevel(9);
         //$client->clearDebug();
         if ($client->getError()) {
             throw new Exception("Initialising soap client failed, invalid wsdl?");
         }
         $this->client = $client;
     }
     return $this->client;
 }
Пример #3
0
 /**
  * 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;
 }