Skip to content

Instantly share code, notes, and snippets.

@vyper
Created June 11, 2012 00:29
Show Gist options
  • Save vyper/2907844 to your computer and use it in GitHub Desktop.
Save vyper/2907844 to your computer and use it in GitHub Desktop.
// configurações de conexão
$username = "admin";
$password = "admin";
$created = date ("Y-m-d\TH:i:s", mktime (date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")))."Z";
// definição de namespaces
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$wsu = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
// criando elemento UsernameToken
$token = new stdClass;
$token->Username = new SOAPVar($username, XSD_STRING, null, null, null, $ns);
$token->Password = new SOAPVar($password, XSD_STRING, null, null, null, $ns);
// criando elemento Timestamp
$timestamp = new stdClass;
$timestamp->Created = new SOAPVar($created, XSD_STRING, null, null, null, $wsu);
// criando elemento Security
$wsec = new stdClass;
$wsec->UsernameToken = new SoapVar($token, SOAP_ENC_OBJECT, null, null, null, $ns);
$wsec->Timestamp = new SoapVar($timestamp, SOAP_ENC_OBJECT, null, null, null, $wsu);
// criando header
$headers = new SOAPHeader($ns, 'Security', $wsec);
// construtor do web-service (com cabeçalho) passando o endereço do WSDL
$client = new SoapClient("http://localhost:8280/services/Tutorial?wsdl");
$client->__setSOAPHeaders($headers);
// chamada do método
try {
$obj = $client->searchProductsByGroupId(array("group_id" => 1));
print_r($obj);
} catch (Exception $e) {
echo "ERRO: " . $e->getMessage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment