Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.43 KB | None | 0 0
  1. <?php                                                                                                                                                  
  2. class API_Client {                                                                                                                                    
  3.        private static $instance = NULL;                                                                                                                
  4.        private function __construct() {                                                                                                                
  5.        }                                                                                                                                              
  6.  /**     * Return client instance or create initial                                                                                                    
  7.   *                                                                                                                                                    
  8.   * @todo save session id or set var or something so each soap call doesn't need to auth                                                              
  9.   * @return object                                                                                                                                    
  10.   * @access public                                                                                                                                    
  11.   */                                                                                                                                                  
  12.   public static function getInstance() {                                                                                                              
  13.      if (!self::$instance) {                                                                                                                          
  14.         echo "Eccomi qua";                                                                                                                            
  15.         $ns   = "auth";                                                                                                                                
  16.         $wsdl = "https://pi731.dncsrl.com/sap/bc/soap/wsdl?services=RFC_SYSTEM_INFO";                                                                  
  17.         //Create our Auth Object to pass to the SOAP service with our values                                                                          
  18.         echo "Sto inserendo i parametri di autenticazione";                                                                                            
  19.         $auth->username = 'j2ee_admin';                                                                                                                
  20.         $auth->password = 'abcd1234!';                                                                                                                
  21.         $auth_vals    = new SoapVar($auth, SOAP_ENC_OBJECT);                                                                                          
  22.         //The 2nd variable, 'authenticate' is a method that exists inside of the SOAP service (you must create it, see next example)                  
  23.         $authenticate = new SoapHeader($ns,'authenticate',$auth_vals, false);                                                                          
  24.         $client = new SoapClient($wsdl,array('cache_wsdl' => 0));                                                                                      
  25.         $client->__setSoapHeaders(array($authenticate));                                                                                              
  26.         self::$instance = $client;                                                                                                                    
  27.         echo "sto per eseguire la chiamata";                                                                                                          
  28.      }                                                                                                                                                
  29.      return self::$instance;                                                                                                                          
  30.   }                                                                                                                                                    
  31.  
  32.  
  33.   private function __clone(){                                                                                                                          
  34.   }                                                                                                                                                    
  35. }   //These are a few sample calls to functions inside of the WSDL                                                                                    
  36.                                                                                                                                                        
  37. try {                                                                                                                                                  
  38.         echo "Eseguo la chiamata";                                                                                                                    
  39.         $data_1 = API_Client::getInstance();                                                                                                          
  40.         echo "Stampo il risultato";                                                                                                                    
  41.         echo $data_1;                                                                                                                                  
  42. }catch (Exception $e){                                                                                                                                
  43.         echo $e->getMessage();                                                                                                                        
  44. }                                                                                                                                                      
  45.                                                                                                                                                        
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement