Guest User

Untitled

a guest
Jul 8th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <?php
  2. class WsseAuthHeader extends SoapHeader
  3. {
  4.  
  5. private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
  6.  
  7. function __construct($user, $pass, $ns = null) {
  8. if ($ns) {
  9. $this->wss_ns = $ns;
  10. }
  11.  
  12. $auth = new stdClass();
  13. $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  14. $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
  15.  
  16. $username_token = new stdClass();
  17. $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
  18.  
  19. $security_sv = new SoapVar(
  20. new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
  21. SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
  22. parent::__construct($this->wss_ns, 'Security', $security_sv, true);
  23. }
  24. }
  25.  
  26. try {
  27. $wsse_header = new WsseAuthHeader('user', 'password');
  28. $x = new SoapClient('http://example.com/Service/CTOProduct.svc?wsdl', array("trace" => 1, "exception" => 0, 'soap_version' => SOAP_1_2));
  29. $x->__setSoapHeaders(array($wsse_header));
  30. } catch(Exception $e) {
  31. exit("SoapClient Error "".$e->getMessage().""");
  32. }
  33.  
  34. if(!empty($x)) {
  35. try {
  36. $response = $x->__soapCall("GetProductByPartNo", array("2014",true));
  37. var_dump($response);
  38. } catch (SoapFault $e) {
  39. exit("Error using Method "GetProductByPartNo" having errorCode test "".$e->faultcode.""");
  40. }
  41. }`enter code here`
  42. ?>
Add Comment
Please, Sign In to add comment