Help with WSSE SOAP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ferke1107
Forum Newbie
Posts: 1
Joined: Fri Nov 11, 2011 2:54 am

Help with WSSE SOAP!

Post by ferke1107 »

Help me please: I have this code, and returns with 'Could not connect to host' errostring. After the initializing soapclient the getFunctions and getTypes functions are correct. What is my mistake?

Thx!

Code: Select all

<?php

require('soap_wsse.php'); 

class mySoap extends SoapClient { 
  function __doRequest($request, $location, $saction, $version) { 
    $doc=new DOMDocument('1.0'); 
    $doc->loadXML($request); 
    $objWSSE=new WSSESoap($doc); 
    $objWSSE->addUserToken($this->_login,$this->_password); 
    return parent::__doRequest($objWSSE->saveXML(), $location, $saction,
$version); 
  } 
} 
//message parameter type:
class getTajInfoElement { 
  public $ruser=null,$mode=null,$taj=null; 
  public $szVezetek=null,$szUtonev1=null,$szUtonev2=null; 
  public $szHely=null,$szEv=null,$szHo=null,$szNap=null; 
  public $neme=null; 
  public $aVezetek=null,$aUtonev1=null,$aUtonev2=null; 
  public $date=null; 
} 
//The wsdl file:
$wsdl='http://tesztjogviszony.oep.hu/ojote/TAJInfoSoapHttpPort?WSDL'; 
//Az eredmény kiiratása 
function printResult($res){ 
  echo "User: ".$res->user."<br/>"; 
  echo "Transaction code: ".$res->tranKod."<br/>"; 
  echo "Error code: ".$res->hibaKod."<br/>"; 
  echo "Error text: ".utf8_decode($res->hibaSzoveg)."<br/>"; 
  echo "Result: ".$res->jogviszony."<br/>"; 
}
//Call web service
try { 
  $sClient=new mySoap($wsdl, array('trace'=>1,'login' => "teszt",
'password' => "Teszt1")); 
  $sClient->login(); 
  $tie=new getTajInfoElement(); 
  $tie->ruser="teszt"; $tie->mode="01"; 
  $tie->szVezetek=iconv ( "ISO-8859-2", "UTF-8", "xxx"); 
  $tie->szUtonev1=iconv ( "ISO-8859-2", "UTF-8", "xxx"); 
  $test=$sClient->getTajInfo($tie); 
  printResult($test->result); 
  $tie=new getTajInfoElement(); 
  $tie->ruser="teszt"; $tie->mode="01"; $tie->taj="12"; 
  $test=$sClient->getTajInfo($tie); 
  printResult($test->result); 
} catch (SoapFault $e) { //hiba kezelése 
  echo "Error: ".$e->faultstring."<br/>"; 
} 
?>
The soap_wsse.php file:

Code: Select all

class WSSESoap { 
const WSSENS= 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; 
const WSUNS= 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'; 
const WSSEPFX='wsse'; const WSUPFX='wsu'; 
private $soapNS, $soapPFX; 
private $soapDoc=NULL; 
private $envelope=NULL; 
private $SOAPXPath=NULL; 
private $secNode=NULL; 
public $signAllHeaders=FALSE; 
public function __construct($doc, $bMustUnderstand=TRUE, $setActor=NULL) { 
 $this->soapDoc=$doc; 
 $this->envelope=$doc->documentElement; 
 $this->soapNS=$this->envelope->namespaceURI; 
 $this->soapPFX=$this->envelope->prefix; 
 $this->SOAPXPath=new DOMXPath($doc); 
 $this->SOAPXPath->registerNamespace('wssoap', $this->soapNS); 
 $this->SOAPXPath->registerNamespace('wswsse', WSSESoap::WSSENS); 
 $this->locateSecurityHeader($bMustUnderstand, $setActor); 
} 
private function locateSecurityHeader($bMustUnderstand=TRUE, $setActor=NULL) { 
 if ($this->secNode == NULL) { 
  $headers=$this->SOAPXPath->query('//wssoap:Envelope/wssoap:Header'); 
  $header=$headers->item(0); 
  if (! $header) { 
   $header=$this->soapDoc->createElementNS($this->soapNS, $this->soapPFX.':Header'); 
   $this->envelope->insertBefore($header, $this->envelope->firstChild); 
  } 
  $secnodes=$this->SOAPXPath->query('./wswsse:Security', $header); 
  $secnode=NULL; 
  foreach ($secnodes AS $node) { 
   $actor=$node->getAttributeNS($this->soapNS, 'actor'); 
   if ($actor == $setActor) { 
    $secnode=$node; 
    break; 
   } 
  } 
  if (! $secnode) { 
   $secnode=$this->soapDoc->createElementNS(WSSESoap::WSSENS, 
WSSESoap::WSSEPFX.':Security' ); 
   $header->appendChild($secnode); 
   if ($bMustUnderstand) { 
    $secnode->setAttributeNS($this->soapNS, $this->soapPFX.':mustUnderstand', '1'); 
   } 
   if (! empty($setActor)) { 
    $secnode->setAttributeNS($this->soapNS, $this->soapPFX.':actor', $setActor); 
   } 
  } 
  $this->secNode=$secnode; 
 } 
 return $this->secNode; 
} 
public function addUserToken($userName, $password=NULL, $passwordDigest=FALSE) { 
 if ($passwordDigest && empty($password)) { 
  throw new Exception("Cannot calculate the digest without a password"); 
 } 
 $security=$this->locateSecurityHeader(); 
 $token=$this->soapDoc->createElementNS(WSSESoap::WSSENS, 
WSSESoap::WSSEPFX.':UsernameToken'); 
 $security->insertBefore($token, $security->firstChild); 
 $username=$this->soapDoc->createElementNS(WSSESoap::WSSENS, 
WSSESoap::WSSEPFX.':Username', $userName); 
 $token->appendChild($username); 
 if ($password) { 
  $passType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-tokenprofile-1.0#PasswordText'; 
  if ($passwordDigest) { 
   $password=base64_encode(sha1($nonce.$createdate. $password, true)); 
   $passType='#PasswordDigest'; 
  } 
  $passwordNode=$this->soapDoc->createElementNS(WSSESoap::WSSENS, 
WSSESoap::WSSEPFX.':Password', $password); 
  $token->appendChild($passwordNode); 
  $passwordNode->setAttribute('Type', $passType); 
 } 
} 
public function saveXML() { 
 return $this->soapDoc->saveXML(); 
} 
}
Post Reply