摘要:PHP調用WCF(HTTPS & BasicHttpBinding & WS-Security[UserName])
header('Content-Type: text/html; charset=utf-8');
try
{
$wsdlPath = "https://service.svc?wsdl";
//USE WS-SECURITY ,WE SET USERNAME AND PASSWORD
$ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
$token = new stdClass;
$token->Username = new SOAPVar('username goes here', XSD_STRING, null, null, null, $ns);
$token->Password = new SOAPVar('password goes here', XSD_STRING, null, null, null, $ns);
$wsec = new stdClass;
$wsec->UsernameToken = new SoapVar($token, SOAP_ENC_OBJECT, null, null, null, $ns);
$headers = new SOAPHeader($ns, 'Security', $wsec, true);
$client = new SoapClient($wsdlPath);
$client->__setSOAPHeaders($headers);
$params=array("strNo"=>"EP09-00044"); //Put the service parameters here
$response = $client->GetList($params);
$result = $response->GetListResult;
print_r($result->PO->PONo);//The easyest way to see the result.
}
catch(Exception $e)
{
echo $e->getMessage();
}
人生到處知何似
應似飛鴻踏雪泥