Advertisement
lucasjv92

Untitled

Jan 7th, 2019
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. <?php
  2. class WsseAuthHeader extends SoapHeader
  3. {
  4.     private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  5.     function __construct($user, $pass, $ns = null)
  6.     {    
  7.         if ($ns)
  8.         {        
  9.             $this->wss_ns = $ns;    
  10.         }    
  11.  
  12.         $auth = new stdClass();    
  13.  
  14.         $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);    
  15.         $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);    
  16.         $username_token = new stdClass();    
  17.         $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);    
  18.         $security_sv = new SoapVar(        
  19.                                 new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),        
  20.                                 SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);    
  21.  
  22.         parent::__construct($this->wss_ns, 'Security', $security_sv, true);
  23.     }
  24. }
  25.  
  26. try
  27. {
  28.  
  29.     $options = array(
  30.         'soap_version'    => SOAP_1_2,
  31.         'exceptions'      => true,
  32.         'trace'           => true,
  33.         'wdsl_local_copy' => true,
  34.         );
  35.    
  36.  
  37. $username = "User";
  38. $password = "Password";
  39.  
  40. $wsse_header = new WsseAuthHeader($username, $password);    
  41. $endPointURI = "https://localhost:88776/SoapTEST/services/securityservice.svc?wsdl";
  42. $client = new SoapClient($endPointURI, $options);
  43. $client->__setSoapHeaders(array($wsse_header));
  44.  
  45.  
  46. print_r($client->__getFunctions());
  47.  
  48. $retval = $client->GetDocuments();
  49.  
  50. print_r($retval);
  51. }
  52. catch(Exception $e)
  53. {
  54.     echo "<h2>Exception Error!</h2></b>";
  55.     echo $e->getMessage();
  56. }
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement